title: .net core file transfer to network location
body: <p>I have code to transfer files from one location to a network drive. The source location may be my pc or another network drive. I am using .NET Core 2.1 and C#.  I have code similar to what I have below from MSDN examples.</p>
  
  <p>The problem is that this works fine when the target is a folder on my PC, but when it is a network location like below, the file is not moved to the specified location. The file in the source does get removed though and there are no errors whatsoever. </p>
  
  <p>I have ensured that the windows account I'm logged in with has explicit permissions to the network location. I'm assuming that is the context my application is running under. I have also looked around and tried to do impersonation to explicitly use an account with permissions and found some code to do it, but it seems as though that does not work in .net core.</p>
  
  <p>What am I missing? How can I get this to work?</p>
  
  <pre><code>string fileName = @"TestFile.txt";
  string sourcePath = @"C:\users\myuser\docs";
  string targetPath =  @"\\10.10.10.148\docs";
  
  // Use Path class to manipulate file and directory paths.
  string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
  string destFile = System.IO.Path.Combine(targetPath, fileName);
  
  // To copy a folder's contents to a new location:
  // Create a new target folder, if necessary.
  if (!System.IO.Directory.Exists(targetPath))
  {
      System.IO.Directory.CreateDirectory(targetPath);
  }
  
  // To copy a file to another location and 
  // overwrite the destination file if it already exists.
  System.IO.File.Move(sourceFile, destFile, true);
  </code></pre>