个人补充: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(
"./")+"\\文件名")   ;   
  }
 
posted on 2007-05-11 15:20  刺猬博客  阅读(570)  评论(0)    收藏  举报