First Include Heder files and assembly files to your Web page:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Permissions;
using Microsoft.Win32;
using System.Windows.Forms;
using System.IO;
[assembly: RegistryPermission(SecurityAction.RequestMinimum, ViewAndModify = "HKEY_CURRENT_USER\\SOFTWARE\\MICROSOFT\\INTERNET EXPLORER\\TYPEDURLS")]
[assembly: RegistryPermission(SecurityAction.RequestMinimum, ViewAndModify = "HKEY_CURRENT_USER\\SOFTWARE\\MICROSOFT\\INTERNET EXPLORER")]
Then use this code:
//below is the textBox for deleting particular Cache from your Browser
string enteredtext = txt_url.Text.Trim();
string lowertext = txt_url.Text.ToLower();
string uppertext = txt_url.Text.ToUpper();
string[] internetcachefile = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache), "*", SearchOption.AllDirectories);
for (int i = 0; i < internetcachefile.Count(); i++)
{
try
{
if (internetcachefile.ElementAt(i).Contains(enteredtext) || internetcachefile.ElementAt(i).Contains(lowertext) || internetcachefile.ElementAt(i).Contains(uppertext))
{
File.Delete(internetcachefile.ElementAt(i));
lbl_message.Text = "Cache cleared";
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
No comments:
Post a Comment