Internet Cache Returns Wrong Directory

Hi,

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)
  {
    myDirectoryInfo.Create();
  }
 
  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);
    File.Delete(myCache);
  }
 
  //Delete the directory.
  myDirectoryInfo.Delete(true);
  HttpContext.Current.Response.Write(myCache_1);
}

Open in new window

tedporterIT Technical Services ConsultantAsked:
Who is Participating?
 
Bernard S.CTOCommented:
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?

0
 
tedporterIT Technical Services ConsultantAuthor Commented:
Hi,

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.
0
 
Bernard S.CTOCommented:
B-)) Glad it helped, thx for the grade and points.
B-( Sorry for the bad news that your initial plan will not work
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.