Internet Cache Returns Wrong Directory

Posted on 2009-02-16
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

Question by:tedporter
    LVL 29

    Accepted Solution

    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?


    Author Closing Comment


    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.
    LVL 29

    Expert Comment

    B-)) Glad it helped, thx for the grade and points.
    B-( Sorry for the bad news that your initial plan will not work

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
    This Micro Tutorial will demonstrate how nuggets on the Web are formatted by using Chrome Developer Tools. These tools would not only view the site's CSS but it can also modify it and save the CSS to use on your own site.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now