title: C# Console App Moving File using AD credentials (non local)
body: <p>I'm having a bit of an issue trying to get a file moved using a different set of credentials. I have 2 machines, 1 machine is a laptop the other is a server. When a user opens my console app, It grabs a file and moves the file over to the server using an AD account with access to write to the server.</p>
  
  <p>I'm having difficulties trying to get impersonation to work. I have the following code:</p>
  
  <pre><code>  AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
  
              WindowsIdentity idnt = new WindowsIdentity("test@test.com", "test");
  
              WindowsImpersonationContext context = idnt.Impersonate();
  
  
  
  
              for (int i = 0; i &lt; filePaths.Count; i++)
              {
                  string[] fileSplit = filePaths[i].Split('\\');
                  if (!File.Exists(targetLocation))
                  {
  
                     Console.Write(File.Exists("C:\\New_folder\\test.txt"));
                     //File.Move("\\\\ITL105076\\c$\\test.txt", targetLocation );
                  }
              }
              context.Undo();
  </code></pre>
  
  <p>all it does is returns true or false if the file exists or not. If I run the application with impersonation the file check returns as false. If I run the application without impersonation it returns true.</p>
  
  <p>To further test, I looged in to the laptop as the "test" user and it still yielded me the same results. If the application impersonates the user that is currently using it, it is still false and impersonation is removed then it returns true..</p>
  
  <p>How do I make impersonation work so I can move files from the laptop to server with credentials separate from the user in AD???</p>