使用c#在网络上移动目录

时间:2012-06-20 10:32:20

标签: c# networking directory

我有一个文件夹A,我想把它从我的电脑移到网络上的服务器上。

我已尝试Directory.Move(A,Server),但由于它们没有相同的根,因此无效。

File.Copy(A,Server)无效,因为该文件夹是只读的,无法更改权限。

提前致谢。

编辑 包含代码

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

这是我目前使用的代码。

编辑2

我的计算机和服务器位于不同的域中。

1 个答案:

答案 0 :(得分:1)

正如@Tigran建议的那样,您可以将cmd与xcopy一起使用(如果您愿意,也可以使用robocopy。)

尝试使用:

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