Move a directory across a network using c#

半城伤御伤魂 提交于 2019-12-25 08:57:27

问题


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.


回答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);


来源:https://stackoverflow.com/questions/11117700/move-a-directory-across-a-network-using-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!