We help IT Professionals succeed at work.

Internet Cache Returns Wrong Directory

Medium Priority
Last Modified: 2012-05-06

I am trying to clear the Tempoary Internet Files from my PC using C#. I have manually checked where they are sitting which is "C:\Documents and Settings\EPorter\Local Settings\Temporary Internet Files".

However, my code is returning "C:\Documents and Settings\EGP\ASPNET\Local Settings\Temporary Internet Files ", where EGP is the name of my PC.

Not sure what is going on but could do with some help please - thanks.
public void ClearIECache()
  DirectoryInfo myDirectoryInfo = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache));
  if (myDirectoryInfo.Exists == false)
  string myCache_1 = myDirectoryInfo.FullName;
  string[] myChache_2;
  File.SetAttributes(myCache_1, FileAttributes.Normal);
  myChache_2 = System.IO.Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache));
  //Get all files in Temporary internet
  foreach (string myCache in myChache_2)
    //files, folder and then set their attribute to normal then delete
    File.SetAttributes(myCache, FileAttributes.Normal);
  //Delete the directory.

Open in new window

Watch Question

Both answers / addresses are correct, although they relate to different uses...

Your C# program uses "its" cache under ASPNET...
Not sure that the security option will allow this program to access "your" cache...

In fact this is probably forbidden (or this is a safety hole):
Imagine that the C# program is running on a remote server... would it be OK for it to access files on your machine?

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
tedporterIT Technical Services Consultant



I have tested both locally (XP) and remotley (Server 2003) on IIS and your definition is correct. Oh well, back to the drawing board!

Thanks for you help.

B-)) Glad it helped, thx for the grade and points.
B-( Sorry for the bad news that your initial plan will not work
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.