这是删除图片的代码
    public class deleteimg : System.Web.UI.Page
    {
        //删除文件夹图片
        public void DeleteDiskFile(string ImageUrl)
        {
            try
            {
                string FilePath = Server.MapPath(ImageUrl);//转换物理路径         
                 File.Delete(FilePath);//执行IO文件删除,需引入命名空间System.IO;        
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
这是传递一个值给上面类
                StringBuilder sqlimg = new StringBuilder();//删除上传的图片
                sqlimg.Append("select BOOK_IMGURL from BS_BookInfo where ");
                sqlimg.Append("   ID in ('").Append(key).Append("') ");
                delimg.DeleteDiskFile(sqlimg.ToString());
这是图片存储到数据库里面的路径数据:/UploadImages/BooKImages/1357890188656.jpgasp.net数据库

解决方案 »

  1.   

    你代码没错。
    你是执行没反应还是怎么的?
    调用 File.Delete(FilePath);之前先调用File.Exists(FilePath)判断下文件是否存在吧
      

  2.   

    删除数据库的数据跟能不能删除服务器上的图片没有关系的
    要删除这个图片首先要有权限,然后要确保File.Delete(FilePath) 中的FilePath是正确的
      

  3.   

            string path = Server.MapPath("~/images/Article");
            foreach (string fileName in System.IO.Directory.GetFiles(path))
            {
                string newName = fileName.Substring(fileName.LastIndexOf("\\") + 1);
                System.IO.File.Delete(path + "\\" + newName);//删除
            }
      

  4.   

    Refer:
    http://www.cnblogs.com/insus/articles/1431986.html