0

I have a folder A, I want to move it from my computer to a server on the network.

I've tried Directory.Move(A,Server) but because they don't have the same root it does not work.

File.Copy(A,Server) won't work as the folder is read only and can't change permissions.

Thanks in advance.

EDIT inculding code

string copyFrom = @"folder";
string copyTo = @"\\server\Libraries\Documents";
string destinationPath = Path.Combine(copyTo, Path.GetFileName(copyFrom));
File.Copy(copyFrom, destinationPath);

That is the code I am currently using.

EDIT 2

My computer and Server are on different domains.

ELSheepO
  • 305
  • 3
  • 9
  • 26

1 Answers1

1

As @Tigran suggested, you can use cmd with xcopy (or robocopy if you prefer).

Try using this:

ProcessStartInfo Info = new ProcessStartInfo(); 
Info.Arguments = "/C xcopy C:\A \\server\A /I /E /Y"; 
Info.WindowStyle = ProcessWindowStyle.Hidden; 
Info.CreateNoWindow = true; 
Info.FileName = "cmd.exe"; 
Process.Start(Info);
Bali C
  • 30,582
  • 35
  • 123
  • 152
  • Anychance you have an easy way to log onto the server?? – ELSheepO Jun 20 '12 at 11:01
  • @ELSheepO I don't know what you mean? – Bali C Jun 20 '12 at 11:06
  • `Logon failure: unknown user name or bad password.` I get this exception when I run the code. – ELSheepO Jun 20 '12 at 12:19
  • Sorry, I meant running the `xcopy` command from cmd, it might give you a better idea where it's going wrong. VS error will be different from what cmd will be reporting. – Bali C Jun 20 '12 at 12:33
  • Its giving me a `invalid drive specification` when i use the ip of the server and the server name `\\server\c:\folder_test` – ELSheepO Jun 20 '12 at 12:48
  • That is an invalid drive path, try using the share - `\\server\c$\folder_test` – Bali C Jun 20 '12 at 12:50
  • `xcopy folder* \\servername\c$\folder_test` and replacing with the ip don't work. I changed the directory to where the folder is to see if that was the problem, but that didn't work either – ELSheepO Jun 20 '12 at 13:06