Asp.net deletes all files in the folder.

Source: Internet
Author: User

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 );
}
}
}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.