title: C# Copy file to folder with permissions
body: <p>I'm writing a program that, among other things, needs to copy a particular file to a network folder. Since I'm on a company network, the credentials needed to access that folder are the same as my Windows credentials.</p>
  
  <p>The program works if I open the folder in Explorer, provide my username and password, and then run the uploader. It doesn't work without first providing that username and password.</p>
  
  <p>How do I tell System.IO to supply my DefaultNetworkCredentials to the Copy method? Or is there another method I can use to get this done?</p>
  
  <pre><code>string pathToFile = "myfile.csv";
  string pathToRemoteFile = "\\server.domain.tld\Documents\Subfolder\myfile.csv"
  
  System.IO.File.Copy(pathToFile, pathToRemoteFile); // Fails with IOException "can't find network path"
  </code></pre>
  
  <p>Thanks!</p>
  
  <p>~ Wogan</p>