2

Possible Duplicate:
Copy file on a network shared drive
Access a Remote Directory from C#
How to pass credentials during writting file at server path?

How do I save a file into a shared folder of a server from my WPF and C# application. I have the IP and the credentials of the server and have given Read/Write permission to the shared folder.

AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
            WindowsIdentity identity = new WindowsIdentity(username, password);
            WindowsImpersonationContext context = identity.Impersonate();

            try
            {
                File.Copy(@"d:\MyFile.txt", @"\\1.2.3.4\CopyData\Myfile.txt", true);
            }
            catch (Exception)
            {                    
                context.Undo();
            }

Getting the following exception :

"The name provided is not a properly formed account name."

Community
  • 1
  • 1
HotTester
  • 5,620
  • 15
  • 63
  • 97

0 Answers0