如何删除文件夹中的图片,文件。 如何删除文件夹中的图片,文件。 file.delete() 里面必须传递的是绝对路径,有没有相对路径的。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用这个插件吧,http://download.csdn.net/source/303617很方便 using System.IO;string strFilePath = Server.MapPath("..\\newspicture\\"+文件名);if(File.Exists(strFilePath)){ File.Delete(strFilePath);//删除原来图片} using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;/// <summary>/// DeleteFilePic 的摘要说明/// </summary>namespace Tools{ public class DeleteFilePic { public static void SetListBoxItem(ListBox listBox, string sItemValue) { int index = 0; foreach (ListItem item in listBox.Items) { ///判断值是否相等,并且设置控件的SelectedIndex if (item.Value.ToLower() == sItemValue.ToLower()) { listBox.SelectedIndex = index; break; } index++; } } public static void SetListBoxItem(DropDownList listBox, string sItemValue) { int index = 0; foreach (ListItem item in listBox.Items) { ///判断值是否相等,并且设置控件的SelectedIndex if (item.Value.ToLower() == sItemValue.ToLower()) { listBox.SelectedIndex = index; break; } index++; } } /// 删除文件文件或图片 /// </summary> /// <param name="path">当前文件的路径</param> /// <returns>是否删除成功</returns> public static void FilePicDelete(string path) { System.IO.FileInfo file = new System.IO.FileInfo(path); if (file.Exists) { file.Delete(); } } }} string savePath = @"../UploadFiles/";if ((extension == ".jpg") | (extension == ".gif")) { ImageName = DateTime.Now.ToString("yyyyMMddhhmmssfff") + extension;savePath += ImageName;savePath3 = Server.MapPath(savePath3);//删除旧图片 DeleteFilePic.FilePicDelete(savePath3); 问什么非得要相对路径的,其实相对路径和绝对路径内部找的方式是一样的,只不过相对路径内部实现是在前面加上了驱动器的一串前缀,你可一用system.io.directory.getCurrentDirectory()或者Application.StartupPath获得当前工作路径(bin目录),然后加上图片的路径,很容易获得图片的引用,这样完全可以做到删除图功能。 请教asp.net中一个正则表达式替换的问题 自定义验证控件的简单应用 类型疑问 求.net c# 存储过程 教程 datagird 求救:我的DropDownList怎么不能赋初值???? 北京寻asp.net开发人员,可兼职(需在北京) 如果session失效,转换不成功,会出现什么异常啊? 问一个初级的问题 l = Convert.ToInt32(a3) * Convert.ToInt32(aa5);????出错 求助:在APS.NET中如何用buttom事件添加treeview的节点? Cookie.HttpOnly 属性为什么无效?
http://download.csdn.net/source/303617
很方便
if(File.Exists(strFilePath))
{
File.Delete(strFilePath);//删除原来图片
}
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;/// <summary>
/// DeleteFilePic 的摘要说明
/// </summary>
namespace Tools
{
public class DeleteFilePic
{
public static void SetListBoxItem(ListBox listBox, string sItemValue)
{
int index = 0;
foreach (ListItem item in listBox.Items)
{
///判断值是否相等,并且设置控件的SelectedIndex
if (item.Value.ToLower() == sItemValue.ToLower())
{
listBox.SelectedIndex = index;
break;
}
index++;
}
} public static void SetListBoxItem(DropDownList listBox, string sItemValue)
{
int index = 0;
foreach (ListItem item in listBox.Items)
{
///判断值是否相等,并且设置控件的SelectedIndex
if (item.Value.ToLower() == sItemValue.ToLower())
{
listBox.SelectedIndex = index;
break;
}
index++;
}
} /// 删除文件文件或图片
/// </summary>
/// <param name="path">当前文件的路径</param>
/// <returns>是否删除成功</returns>
public static void FilePicDelete(string path)
{
System.IO.FileInfo file = new System.IO.FileInfo(path);
if (file.Exists)
{
file.Delete();
}
}
}
}
if ((extension == ".jpg") | (extension == ".gif"))
{
ImageName = DateTime.Now.ToString("yyyyMMddhhmmssfff") + extension;
savePath += ImageName;
savePath3 = Server.MapPath(savePath3);
//删除旧图片
DeleteFilePic.FilePicDelete(savePath3);