這是一個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 –