How to use. Net to clear ie cache (Temporary Internet Files)

Source: Internet
Author: User

If you want to write a. netCodeTo search for the Internet, you should be able to find such code:

 
VoidEmptycachefolder (directoryinfo folder)
 
{
Foreach(Fileinfo FileInFolder. getfiles ())
 
{
File. Delete ();
 
}
 
 
Foreach(Directoryinfo subfolderInFolder. getdirectories ())
{
 
Emptycachefolder (subfolder );
}
 
}
 
 
 
// Function which is used for clearing the cache
 
BoolSort AchE ()
{
 
BoolEmpty;
Try
 
{
Emptycachefolder (NewDirectoryinfo (environment. getfolderpath (environment. specialfolder. internetcache )));
 
Empty =True;
}
 
 
Catch
 
{
Empty =False;
 
}
 
 
ReturnEmpty;
 
 
}

 

But when you actually run this code, you find that there is no way to make the code run stably, and the files in the IE cache directory cannot be deleted. Why?

In this Code, when you try to delete files in the Temporary Internet Files directory, some files are system files or are being used by browsers, io exception will be thrown, and the entire foreach loop will be terminated.

First, we should put the code in try to ensure that the loop will not be terminated due to exception. Second, for files with IO conflicts that cannot be deleted, we should register it as automatic deletion at next startup, in this way, the IE cache files can be thoroughly removed.

For specific code, refer:

Your Internet Explorer's secrets

Related Article

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.