Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.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# 如何从服务器获取要删除的文件的路径_C#_.net_Asp.net_File Io - Fatal编程技术网

C# 如何从服务器获取要删除的文件的路径

C# 如何从服务器获取要删除的文件的路径,c#,.net,asp.net,file-io,C#,.net,Asp.net,File Io,我想删除服务器上目录中的文件。我尝试了以下代码,但file.exist中的代码从未运行。它总是跳过它,告诉我文件不存在。但文件是存在的。斯蒙能帮帮我吗。先发制人 string filename = "Template\\copy.jpg"; if(System.IO.File.Exists(filename)) { System.IO.File.Delete(filename); } 试一试 试一试 您可以使用Server

我想删除服务器上目录中的文件。我尝试了以下代码,但file.exist中的代码从未运行。它总是跳过它,告诉我文件不存在。但文件是存在的。斯蒙能帮帮我吗。先发制人

string filename = "Template\\copy.jpg";
        if(System.IO.File.Exists(filename))
        {
            System.IO.File.Delete(filename);
        }
试一试

试一试


您可以使用
Server.MapPath
获取路径。e、 g

string filename = Server.MapPath("~/Template/copy.jpg");
System.IO.File.Delete(filename);

您可以使用
Server.MapPath
获取路径。e、 g

string filename = Server.MapPath("~/Template/copy.jpg");
System.IO.File.Delete(filename);

在将“~/”路径传递到Server.MapPath之前,您可能需要在“~/”路径上调用ResolveUrl。在将该路径传递到Server.MapPath之前,您可能需要在“~/”路径上调用ResolveUrl。