asp.net图片上传后,图片实际删除总结

来源:互联网 发布:淘宝直播账号怎么申请 编辑:程序博客网 时间:2024/05/18 02:46

个人补充:Server.MapPath()中路径从数据库中读取如/aa/bb/cc.jpg

删除得有~符号

读取后添加~就是读取值=“~”+读取值;

一、

引入using   System.IO;  

SqlConnection   conn   =   new   SqlConnection(strConnectionString);  
  string   SQL   =   "select   img_url   from   图片所在的表   where   img_id   =   @id";  
  SqlCommand   cmd   =   new   SqlCommand(SQL,conn);  
  cmd.CommandType   =   CommandType.StoredProcedure;  
  cmd.Parameters.Add("@id",SqlDbType.Int);  
  cmd.Parameters["@id"].Value   =   图片ID号;  
  conn.open  
  string   filePath   =   cmd.ExecuteScalar().ToString();  
  if(File.Exists(filePath))              
  {  
        File.Delete(filePath)   ;  
  }  
  conn.Close();    

二、

引入using   System.IO;   
     if(File.Exists(Server.MapPath("./")+"//文件名")   ==   true)              
  {  
        File.Delete(Server.MapPath("./")+"//文件名")   ;  
  }  

原创粉丝点击