Click here to Skip to main content
15,888,148 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I clean Internet Cache using C# Windows application in VS 2005.
Posted

1 solution

The internet cache files are stored in 'Temporary Internet Files' folder. So basically what you need to do is to delete all the files that are present in that folder. In order to do this;

C#
private void EmptyCacheFolder(DirectoryInfo folder)
{
    foreach (FileInfo file in folder.GetFiles())
    { 
        file.Delete(); 
    }
    foreach (DirectoryInfo subfolder in folder.GetDirectories())
    { 
        EmptyCacheFolder(subfolder); 
    }
}

public bool ClearCache()
{
    bool isEmpty;
    try
    {
        EmptyCacheFolder(new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)));
        isEmpty = true;
    }
    catch
    {
        isEmpty = false;
    }    
    return isEmpty;
}
 
Share this answer
 
v2
Comments
Praveen Kullu 6-Aug-11 0:38am    
Note that this will work only for internet explorer cache. If you use firefox or chrome, you will have to find the directory name. The cache folder for both usually resides in %root%/users/<username>/local/...Mozilla or google.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900