Connecting / Copying from network drive

后端 未结 1 1392
小蘑菇
小蘑菇 2021-01-06 08:08

Not totally sure how to approach this. I\'ve researched a bit but I\'ve come up short. Trying to connect to the network drives at work and copy out the newest folder (update

相关标签:
1条回答
  • 2021-01-06 08:38

    You can try with something like this (specifying access rights for the network share ):

    string updir = @"\\NetworkDrive\updates\somefile";
    
    AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
    WindowsIdentity identity = new WindowsIdentity(username, password);
    WindowsImpersonationContext context = identity.Impersonate();
    
    File.Copy(updir, @"C:\somefile", true);
    
    0 讨论(0)
提交回复
热议问题