Wednesday, December 30, 2009

Delete Temp File from Browser

In this code the header files and assembly files are same as Delete Cache which i post early

and the code is:

//textBox is used for deleting particular Temp Files

string enteredtext = txt_url.Text.Trim();
string lowertext = txt_url.Text.ToLower();
string uppertext = txt_url.Text.ToUpper();

string[] tempfiles = Directory.GetFiles(Environment.GetEnvironmentVariable("TEMP"), "*", SearchOption.AllDirectories);
for (int i = 0; i < tempfiles.Count(); i++)
{
try
{
if (tempfiles.ElementAt(i).Contains(enteredtext) || tempfiles.ElementAt(i).Contains(lowertext) || tempfiles.ElementAt(i).Contains(uppertext))
{
File.Delete(tempfiles.ElementAt(i));
lbl_message.Text = "TEMP file cleared";
}

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

No comments:

Post a Comment