title: How to save a file to a shared folder in a server via WPF and C#
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1432213/copy-file-on-a-network-shared-drive">Copy file on a network shared drive</a><br>
    <a href="https://stackoverflow.com/questions/5433570/access-a-remote-directory-from-c-sharp">Access a Remote Directory from C#</a><br>
    <a href="https://stackoverflow.com/questions/10415980/how-to-pass-credentials-during-writting-file-at-server-path">How to pass credentials during writting file at server path?</a>  </p>
  </blockquote>
  
  
  
  <p>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.</p>
  
  <pre><code>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();
              }
  </code></pre>
  
  <p>Getting the following exception : </p>
  
  <p><strong>"The name provided is not a properly formed account name."</strong></p>