我正在使用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 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);
最好
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句