日期:2014-05-18 浏览次数:20649 次
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int id = (int)e.Keys["id"];
            int subjectid = int.Parse(DAL.dbHelper.ExecuteScalar("select top 1 pic from table1  where id=" + id.ToString()).ToString());
            string f = BLL.Bizhi.GetPic4(subjectid, id);
            if (File.Exists(f))
                File.Delete(f);
        }
------解决方案--------------------
if (System.IO.File.Exists(imgPath))//imgPath为你的图片路径
{
  try
  {
       System.IO.File.Delete(imgPath);
  }
  catch (Exception)
  {
       Response.Write("无法删除!");
  }
}
else
{
   Response.Write("该Excel不存在!");
}
------解决方案--------------------
if(System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath(Path)))
{
    System.IO.File.Delete(Path);
}
------解决方案--------------------
System.IO.File.Delete(Server.MapPath("~/"+imgPath));
即使图片不存在也不会出错的,所以可以省去判断图片是否存在的语句.