这是删除图片的代码
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());
这是图片存储到数据库里面的路径数据:/UploadImages/BooKImages/1357890188656.jpgasp.net数据库
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());
这是图片存储到数据库里面的路径数据:/UploadImages/BooKImages/1357890188656.jpgasp.net数据库
你是执行没反应还是怎么的?
调用 File.Delete(FilePath);之前先调用File.Exists(FilePath)判断下文件是否存在吧
要删除这个图片首先要有权限,然后要确保File.Delete(FilePath) 中的FilePath是正确的
foreach (string fileName in System.IO.Directory.GetFiles(path))
{
string newName = fileName.Substring(fileName.LastIndexOf("\\") + 1);
System.IO.File.Delete(path + "\\" + newName);//删除
}
http://www.cnblogs.com/insus/articles/1431986.html