Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I create a folder and access in server programmatically using C#

I have used this code:

C#
string path = @"\\MyIP\C$\NEWFOLDER";

try
{
    if (!Directory.Exists(path))
    {
        Directory.CreateDirectory(path);
    }
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}


What I have tried:

Using above code, I can create a folder on my local machine only!
When I try to create a folder on the server machine, I get exception

The user name or password is incorrect

Thank you.
Posted
Updated 4-Sep-16 20:41pm
Comments
Mehdi Gholam 5-Sep-16 2:10am    
The error is self explanatory.

1 solution

You can't just access any machine on your network and create files or directories, and more than the you can access my home without my permission and rearrange the furniture.
To move the chairs in my house you need the key to my front (or back) door - without that you aren't getting in!
With a remote PC, it's the same: unless you can log into the remote PC with a valid username and password combination, you can't affect the hard drive content. And for a path like that, you need to be an admin on the remote PC as changing the root folder of a boot drive is frowned upon these days for security reasons.
Normally, you would give the name of a shared folder on the remote machine in order to access it, or you aren't getting in anyway - and sharing the root is a dangerous thing, so don't expect too many people to do it!
And you probably want to use the ConnectionOptions class[^] to provide the login details for the remote machine.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900