I have a network shared drive ("\serveur\folder") on which I would like to copy file. I can write on the drive with a specific user ("user"/"pass"). How can I access the shared drived with write privilege using C#?
Navigate to the file or folder that needs to be transferred and right click on it. This will bring up a context menu, click on Copy. Go back to This PC and open the G: drive. From there you can select either My Drive (personal drive) or Shared Drives for folders that have been shared to your account.
To move files from My Drive into a shared drive or between shared drives, drag the files into the destination shared drive.
Go the shared folder, which contains files you want to copy to your drive. Select all the files you want to copy. In the upper right corner click on three vertical dots and select “make a copy” The files will then appear in your drive.
Click "Schedule Sync" at the bottom and enable it, then select any schedule sync you like. Then, click “Start Sync” to sync folder to network drive. You can select schedule settings based on different frequencies, specific events or USB drive ( to automatically sync files between computer and flash drive).
Untested code, but it will be similiar to:
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal); // http://pinvoke.net/default.aspx/advapi32/LogonUser.html IntPtr token; LogonUser("username", "domain", "password", LogonType.LOGON32_LOGON_BATCH, LogonProvider.LOGON32_PROVIDER_DEFAULT); WindowsIdentity identity = new WindowsIdentity(token); WindowsImpersonationContext context = identity.Impersonate(); try { File.Copy(@"c:\temp\MyFile.txt", @"\\server\folder\Myfile.txt", true); } finally { context.Undo(); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With