在.net使用DotNetCharting控件生成报表统计图总结 文章中,不少朋友提出“每运行一次DotNetCharting页面,就会生成一个图片,这样图片不是越来越多吗?请问怎样自动删除DotNetCharting生成的图片呢”的问题,于是自己对asp.net删除文件夹里图片的问题进行了处理。
方法参照如下代码:
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
namespace FLX.ComplexQuery
{
/// <summary>
/// deletepic 的摘要说明。
/// </summary>
public class deletepic : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
private void deletefile(System.IO.DirectoryInfo path)
{
foreach(System.IO.DirectoryInfo d in path.GetDirectories())
{
deletefile(d);
}
foreach(System.IO.FileInfo f in path.GetFiles())
{
f.Delete();
}
}
Web 窗体设计器生成的代码
private void Button1_Click(object sender, System.EventArgs e)
{
System.IO.DirectoryInfo path = new System.IO.DirectoryInfo(Server.MapPath("~/ChartImages"));
deletefile(path);
}
}
}
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
namespace FLX.ComplexQuery
{
/// <summary>
/// deletepic 的摘要说明。
/// </summary>
public class deletepic : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
private void deletefile(System.IO.DirectoryInfo path)
{
foreach(System.IO.DirectoryInfo d in path.GetDirectories())
{
deletefile(d);
}
foreach(System.IO.FileInfo f in path.GetFiles())
{
f.Delete();
}
}
Web 窗体设计器生成的代码
private void Button1_Click(object sender, System.EventArgs e)
{
System.IO.DirectoryInfo path = new System.IO.DirectoryInfo(Server.MapPath("~/ChartImages"));
deletefile(path);
}
}
}