Tuesday, March 18, 2014

Clear Chrome 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 "ChromeClearCache.bat")

@echo off

set ChromeDir=C:\Users\%USERNAME%\appdata\Local\Google\Chrome\User Data\Default\Cache

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

2. Now in your C# code include

using System.Diagnostics;

3. Now add following code of C#

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

}

1 comment: