文件存在〜/ NewsPictures /我的代码返回总是false。 我想删除位置〜/ NewsPictures / 1.png名称
中存在的文件 My code:
bool t = false;
String Location = "~/NewsPictures/1.png";
if (File.Exists(Location) == true)
{
t = true;
}
我做错了什么。
答案 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?。