从目录中删除文件

时间:2014-05-04 10:37:14

标签: c# asp.net

文件存在〜/ NewsPictures /我的代码返回总是false。 我想删除位置〜/ NewsPictures / 1.png名称

中存在的文件
 My code: 
bool t = false;
        String Location = "~/NewsPictures/1.png";
        if (File.Exists(Location) == true)
        {
            t = true;
        }

我做错了什么。

1 个答案:

答案 0 :(得分:1)

正如Marvin Smit所说,System.IO.File.Exists不承认'〜'与System.Web.UI.WebControls.FileUpload的做法相同。

正如CodeCaster所说,你需要让Server.MapPath()弥合这个差距。有关详细信息(和示例),请参阅Server.MapPath("."), Server.MapPath("~"), Server.MapPath(@"\"), Server.MapPath("/"). What is the difference?