Results 1 to 5 of 5

Thread: Deleting Internet Explorer Temporary Files in C#

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    121

    Deleting Internet Explorer Temporary Files in C#

    Can anyone tell me why this wont work? I got the right folder path but it will not remove the files in that folder.


    Code:
    DirectoryInfo di = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache));
    foreach (FileInfo fl in di.GetFiles())
    {
    fl.Delete();
    }

  2. #2
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: Deleting Internet Explorer Temporary Files in C#

    Quote Originally Posted by 2MuchRiceMakesMeSick
    Can anyone tell me why this wont work? I got the right folder path but it will not remove the files in that folder.


    Code:
    DirectoryInfo di = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache));
    foreach (FileInfo fl in di.GetFiles())
    {
    fl.Delete();
    }

    By doesn't work, what do you mean, just not deleting or throwing exceptions?

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    121

    Re: Deleting Internet Explorer Temporary Files in C#

    it doesnt delete anything. no errors no exceptions

  4. #4
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: Deleting Internet Explorer Temporary Files in C#

    That folder requires some additional coding. Since index.dat amongst other files will not let you delete them, you have to take into account the access violations. There may be a quicker, cleaner method, but you can do this with recursive searching:

    Code:
            private void safeRecursiveDeleter(string path)
            {
                foreach (string FileName in Directory.GetFiles(path))
                {
                    try
                    {
                        File.Delete(FileName);
                    }
                    catch { Exception ex; }//Certain files WILL give you access violations (index.dat)
                }
                foreach (string DirectoryName in Directory.GetDirectories(path)) 
                {
                    safeRecursiveDeleter (DirectoryName);
                    try
                    {
                        Directory.Delete(DirectoryName, true); //Will kill the recursive search if there is no undeletable files
                    }
                    catch {Exception ex;}
                }
                
        }
    //Called via:
    
                         safeRecursiveDeleter(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache));
    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  5. #5
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: Deleting Internet Explorer Temporary Files in C#

    I don't have enough expertise in C# to play with InterOp and APIs yet.

    I guess you can use the DeleteUrlCacheEntry API to do this. Here is a VB6 example. May be it woun't be hard to convert it in C#

    Edit:

    found a related page in MS Support pages. It may help ? http://support.microsoft.com/kb/326201/EN-US/
    Last edited by iPrank; Mar 26th, 2006 at 12:05 PM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width