Deleting Internet Cache files from local machine using System.IO in c#

In this blog we are going to see, how to delete the InternetCache files using System.IO

Step 1:              Internet Cache Path

C:\Users\laja\AppData\Local\Microsoft\Windows\Temporary Internet Files

Step 2:              Gets the Special Folder

Environment.SpecialFolder specialFolder = Environment.SpecialFolder.InternetCache;

 

Step 3:              Gets the path of the special folder.

string path = Environment.GetFolderPath(specialFolder);

 

Step 4:              Delete all the files from the internet cache.

DeleteAllFiles(new DirectoryInfo(path));

 

 

    //Delete all the files from the path.

        void DeleteAllFiles(DirectoryInfo diPath)

        {

            //Gets the files from the specific directory

            foreach (FileInfo fiCurrFile in diPath.GetFiles())

            {

                fiCurrFile.Delete();

            }

 

            //Getting Sub directories

            foreach (DirectoryInfo diSubFolder in diPath.GetDirectories())

            {

                DeleteAllFiles(diSubFolder); // Call recursively for all subfolders

            }

        }

 

Thanks for reading this article. Have a nice day.

Ebook Download
View all
test-2
Read by 0 people
Download Now!
Learn
View all