How to copy files to a password protected shared folder on another server


I can manually in Windows 7: Type in Run: \\<ip address>\sharedFolder, type in my username and password, a folder opens in Windows Explorer, I can then copy a file to the shared folder.

How can I do this in C#? I can do a File.Copy() but I can't get around the part about specifying the username/password.

Who is Participating?

Improve company productivity with a Business Account.Sign Up

netjgrnautConnect With a Mentor Commented:
...or run NET USE to connect to \\ServerName\IPC$ with a user and password specified.  Then you can write to the \\ServerName\Share of choice without having to map a drive.
arnoldConnect With a Mentor Commented:
Not sure about c#, what about powershell? There are many examples including vbscript.
Within c# you would run net use to map a drive to a unc
DanTartagliaAuthor Commented:
Thanks to both of you. I'll use the NET USE command one way or the other.
netjgrnautConnect With a Mentor Commented:

You might find that discussion helpful, if you want to go the C# route...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.