使用C#在网络上移动目录 [英] Move a directory across a network using c#

查看:56
本文介绍了使用C#在网络上移动目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件夹A,我想将其从我的计算机移至网络上的服务器.

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

我已经尝试过 Directory.Move(A,Server),但是由于它们的根目录不同,因此无法正常工作.

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

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

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

提前谢谢.

编辑 成功代码

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.

编辑2

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

My computer and Server are on different domains.

推荐答案

按照@Tigran的建议,您可以将cmd与xcopy结合使用(如果需要,可以使用robocopy).

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

尝试使用此:

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

这篇关于使用C#在网络上移动目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆