if(System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath(Path)))
{
System.IO.File.Delete(Path);
}
====================================
System.IO.File.Delete(Server.MapPath("~/"+imgPath));
即使图片不存在也不会出错的,所以可以省去判断图片是否存在的语句.
http://topic.youkuaiyun.com/u/20080319/16/14d03d7b-b285-4e8a-97ff-d4423f4a775e.html

本文提供了一段使用C#删除指定路径下文件的代码,并解释了如何不预先检查文件是否存在即可安全地删除文件的方法。
598

被折叠的 条评论
为什么被折叠?



