0

I am using File.Copy to copy the file from my local system to REMOTE Server using below code.
But its giving me error:

Either a required impersonation level was not provided, or the provided impersonation level is invalid.

AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
WindowsIdentity idnt = new WindowsIdentity("username", "password");
WindowsImpersonationContext context = idnt.Impersonate();
File.Copy("LocalFilepath", Path.Combine(@"\\servername\\c\\Folder1\\EmpDetails.xml"), true);

Thanks Gaby , i have tried the platinumdogs.me/2008/10/30/… but now i am getting Exception in copying file saying that -Could not find file "LocalFile" - I have admin rights on Remote Server also.

New Coder
  • 501
  • 2
  • 6
  • 23
  • 1
    `WindowsIdentity(string, string)` constructor does not take in username and password. It takes in username and type. – SF Lee May 05 '14 at 07:30
  • Also check out: [Impersonate with username and password?](http://stackoverflow.com/questions/7710538/impersonate-with-username-and-password) – SF Lee May 05 '14 at 07:36
  • http://platinumdogs.me/2008/10/30/net-c-impersonation-with-network-credentials/ – Gaby May 05 '14 at 07:37
  • Thanks Gaby , i have tried the http://platinumdogs.me/2008/10/30/net-c-impersonation-with-network-credentials/ but now i am getting Exception in copying file saying that -Could not find file LocalFile. – New Coder May 05 '14 at 10:52

0 Answers0