个人补充: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("./")+"\\文件名") ;
}

浙公网安备 33010602011771号