Home > DeveloperSection > Articles > Delete All Temporary Internet Files of IE in CSharp .NET

Delete All Temporary Internet Files of IE in CSharp .NET


C# C# 
Ratings:
2 Comment(s)
 8333  View(s)
Rate this:

Delete All Temporary Internet Files of IE


Here I’m going to demonstrate how to delete all Temporary Internet Files of Internet Explorer through C#.Net.

Example

private void btnDelete_Click(object sender, EventArgs e)

        {

//creating directory info and asigning it the path of internet cache.

DirectoryInfo di = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache));

//assigning no. of directories in the folder to x

            int x = di.GetDirectories().Count();            

//calling clear() method

            clear(di);

            MessageBox.Show("Deleted");

        }

 

//clear() Method

        public void clear(DirectoryInfo di)

        {  

//loop for each file in directory           

            foreach (FileInfo fi in di.GetFiles())

            {

                try

                {

//deleting the file

                    fi.Delete();

                }

                catch (Exception ex)

                {

                    //MessageBox.Show(ex.Message);

                }

            }

//claaing clear() method recursively for each directory in current directory.

            foreach (DirectoryInfo sub in di.GetDirectories())

                clear(sub);

        }

 


Delete All Temporary Internet Files of IE in CSharp .NET

By James Smith on   5 years ago
Hi Haider,
It's really helped me, great job

Thanks 

Delete All Temporary Internet Files of IE in CSharp .NET

By jain eiti on   4 years ago
Hello Haider

When i'm using this code on local server then its working fine ,but when i'm using this code for online project then Environment.GetFolderPath(Environment.SpecialFolder.InternetCache) gives me null value,plz give me solution of this problem so that we can clear temporary internet files for all current user system.

Don't want to miss updates? Please click the below button!

Follow MindStick