In the summary article on. net's use of the DotNetCharting control to generate a Statistical Chart for a report, many friends suggested that "every time the DotNetCharting page is run, an image will be generated. Isn't there more and more images? How can I automatically delete the images generated by DotNetCharting? "The problem is that I have handled the problem of deleting images in the asp.net folder.
The method can be found in the following code:
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. HtmlControls;
Using System. IO;
Namespace FLX. ComplexQuery
{
/** // <Summary>
/// Summary of 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)
{
// Place user code here to initialize the page
}
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 ();
}
}
Code generated by Web form designer # code generated by region Web Form Designer
Override protected void OnInit (EventArgs e)
{
//
// CODEGEN: This call is required by the ASP. NET Web form designer.
//
InitializeComponent ();
Base. OnInit (e );
}
/** // <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void InitializeComponent ()
{
This. Button1.Click + = new System. EventHandler (this. button#click );
This. Load + = new System. EventHandler (this. Page_Load );
}
# Endregion
Private void button#click (object sender, System. EventArgs e)
{
System. IO. DirectoryInfo path = new System. IO. DirectoryInfo (Server. MapPath ("~ /ChartImages "));
Deletefile (path );
}
}
}