Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用asp.net web服务在IIS根目录下将文件从一个目录复制到另一个目录?_C#_Asp.net_Iis - Fatal编程技术网

C# 如何使用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

我正在使用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);
最好的