Wednesday, March 19, 2014

Clear FireFox Cache from C#

I have taken this reference from below URL, but modified some code.

http://www.catonmat.net/blog/clear-privacy-ie-firefox-opera-chrome-safari/

1. Make a .bat file and paste the following lines in that (I saved as "FireFoxClearCache.bat")

@echo off

set DataDir=C:\Users\%USERNAME%\AppData\Local\Mozilla\Firefox\Profiles

del /q /s /f "%DataDir%"
rd /s /q "%DataDir%"

for /d %%x in (C:\Users\%USERNAME%\AppData\Roaming\Mozilla\Firefox\Profiles\*) do del /q /s /f %%x\*sqlite

2. Now in your C# code include

using System.Diagnostics;

3. Now add following code of C#

public static void ClearFireFoxCache()
{
   Process proc = null;
   try
   {
       proc = new Process();
       proc.StartInfo.FileName = "FireFoxClearCache.bat";
       proc.StartInfo.CreateNoWindow = false;
       proc.Start();
       proc.WaitForExit();
   }
   catch (Exception ex)
   {
       Console.WriteLine("Exception Occurred :{0},{1}", ex.Message, ex.StackTrace.ToString());
   }

}

No comments:

Post a Comment