这是一个web应用程序 我有2个pc的:答:192.168.1.200和B:192.168.1.201,我想从A复制到B,这个代码工作是单个PC,但它不工作在网络中。在本地网络中复制文件
protected void Button1_Click(object sender, EventArgs e)
{
string sourcePath = @"D:\Source\";
string[] filePaths = Directory.GetFiles(sourcePath, "*.txt");
foreach (string a in filePaths)
{
CopyFiles(a, a.Replace("D:\\Source\\", "D:\\Source1\\New\\"));
//CopyFiles(a, a.Replace("D:\\Source\\", "192.168.1.201\\Source1\\New\\"));
}
}
private bool CopyFiles(string Source, string Destn)
{
try
{
if (File.Exists(Source) == true)
{
File.Copy(Source, Destn);
return true;
}
else
{
Response.Write("Source path . does not exist");
return false;
}
}
catch (FileNotFoundException exFile)
{
Response.Write("File Not Found " + exFile.Message);
return false;
}
catch (DirectoryNotFoundException exDir)
{
Response.Write("Directory Not Found " + exDir.Message);
return false;
}
catch (Exception ex)
{
Response.Write(ex.Message);
return false;
}
}
如果要将这些文件粘贴到其他计算机桌面上,我将使用IPv4地址,然后提供如下路径:C:\\ Users \\ ASUS \\ Desktop \\? https://stackoverflow.com/a/10883763/9087709 –