C# 如何使用asp.net web服务在IIS根目录下将文件从一个目录复制到另一个目录?
我正在使用win7 IIs服务器开发asp.net web服务。在IIs根目录下有两个子目录。我如何将文件从一个子文件夹复制到另一个子文件夹这是我的尝试:C# 如何使用asp.net web服务在IIS根目录下将文件从一个目录复制到另一个目录?,c#,asp.net,iis,C#,Asp.net,Iis,我正在使用win7 IIs服务器开发asp.net web服务。在IIs根目录下有两个子目录。我如何将文件从一个子文件夹复制到另一个子文件夹这是我的尝试: string fileName="file.txt"; string sourcePath = @"localhost\C:\inetpub\wwwroot\source"; string targetPath = @"localhost\C:\inetpub\wwwroot\dest"; string
string fileName="file.txt";
string sourcePath = @"localhost\C:\inetpub\wwwroot\source";
string targetPath = @"localhost\C:\inetpub\wwwroot\dest";
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
System.IO.File.Copy(sourceFile, destFile, true);
提前感谢您应该使用物理路径。即:
string fileName="file.txt";
string sourcePath = @"C:\inetpub\wwwroot\source";
string targetPath = @"C:\inetpub\wwwroot\dest";
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
System.IO.File.Copy(sourceFile, destFile, true);
如果需要涉及网站根目录(在本例中为网站根目录文件夹上的文件夹),应如下所示:
string fileName="file.txt";
string sourcePath = Server.MapPath("/source");
string targetPath = Server.MapPath("/dest");
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
System.IO.File.Copy(sourceFile, destFile, true);
最好的