日期:2014-05-17 浏览次数:20507 次
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());
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&n