I am trying to copy file from local drive to one of folder on server. name of the folder on server is \'DBFiles\'. No one has got access to this apart from username \'user\'
NetworkShare.DisconnectFromShare(@"\\server-a\DBFiles", true); //Remove this line
NetworkShare.ConnectToShare(@"\\server-a\DBFiles", "user1", "password1!"); //Connect with the new credentials
File.Copy(@"c:\temp\T1.txt", @"\\server-a\DBFiles\T1.txt");
NetworkShare.DisconnectFromShare(@"\\server-a\DBFiles", false); //Remove this line also
After 02 days search in Google finally the above worked for me.
If you use 'NetworkShare.DisconnectFromShare' after the first login you will get an error as 'Access denied'. Then every time you need to restart the server or need to execute 'net use * /del' command to delete the saved credentials in windows.