在.net中,当删除了数据库中存入图片的这条记录时,如果删除在文件夹的这张图片呢?谢谢各位解答!

解决方案 »

  1.   

    Label lblurl = (Label)gridview1.Rows[i].Cells[0].FindControl("lblimaurl");
                            if (!string.IsNullOrEmpty(lblurl.Text.Trim().ToString()))
                            {
                                String path = Server.MapPath("~/UploadedImages/message/") + lblurl.Text.Trim().ToString().Replace("~/UploadedImages/message/", "");
                                if (File.Exists(path))
                                {
                                    File.Delete(path);
                                }
                            }
      

  2.   

    using System.IO;
            public void DeleteFile()
            {
                string path = Server.MapPath("File");//file是寸图片的文件夹
                if (System.IO.Directory.Exists(path))
                {
                    string[] str = System.IO.Directory.GetFiles(path);
                    for (int i = 0; i < str.Length; i++)
                    {
                        string temp = str[i].Substring(str[i].LastIndexOf('\\') + 1);
                        if (temp.Equals("2008-10-07-11-56-43.jpg"))
                        {
                            System.IO.File.Delete(str[i]);//删除某个指定的文件
                        }                }            }
            }
      

  3.   

    主要是取得文件路径和名称,剩下的就简单了,文件的delete方法就OK
      

  4.   

     if (File.Exists(fullpath))//fullpath图片路径
     {
             File.Delete(fullpath);
     }
      

  5.   

    先找到你数据库中保存图片的名字System.IO.FileInfo file = new System.IO.FileInfo(你图片文件夹地址+数据库图片名);
    file .Delete();