suman n m

Hi,

My application has a provision to change the dimensions of an image.

When dimensions of an image are changed, the original image is getting effected,

but the image is getting loaded from the "temporary internet files" folder when

trying to view it and so, the image is viewed with old dimensions.

Deleting temporary files will solave my problem. So, tried a sample code to access internet temp folder.

But to my surprise only one file is seen in strFiles array (desktop.ini), no other files are retrieved.

Sub Main()

Dim strFiles() As String = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache))

End Sub

If I given Environment.SpecialFolder.Desktop, all files are retrieved.

Do I need to set any permission to access internet files,

Please suggest me with some workaround for this.\

Regards,

Suman.N.M



Re: Internet Explorer Extension Development How to delete Temporary Internet Files

AndreyDev

here it is!

Code Block

using System.IO; ...

void clearIECache()
{
ClearFolder (new DirectoryInfo (Environment.GetFolderPath
(Environment.SpecialFolder.InternetCache)));
}

void ClearFolder (DirectoryInfo folder)
{
foreach (FileInfo file in folder.GetFiles())
{ file.Delete(); }
foreach (DirectoryInfo subfolder in folder.GetDirectories())
{ ClearFolder(subfolder); }
}

public static void Main( )
{
new Test().clearIECache ();
}

P.S. in the Environment.SpecialFolder.InternetCache folder really only 1 file !!!

you need to search all subfolders and clear its' too.

Cheers,

Andrey.






Re: Internet Explorer Extension Development How to delete Temporary Internet Files

sumannm

Hi Andrey,

NIce to see your post.

I need to delete all the files and subfolders in Environment.SpecialFolder.InternetCache folder.

I tried your code, but still the same problem.

Regards,

Suman.N.M





Re: Internet Explorer Extension Development How to delete Temporary Internet Files

sumannm

Hi Andrey,

I wrote code in .net 2005, this is working very fine.

But I need it in vb.net 2003, it has only 2 overridden "GetFiles" methods.

static void Main(string[] args)

{

String[] files = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)

,"*.*",System.IO.SearchOption.AllDirectories);

foreach (String filePath in files)

{

try

{

FileInfo f = new FileInfo(filePath);

f.Delete();

}

catch (SecurityException se)

{

continue;

}

catch (UnauthorizedAccessException uae)

{

continue;

}

catch (IOException ie)

{

continue;

}

}

}

Can you help me in getting all files.

Regards

Suman.N.M





Re: Internet Explorer Extension Development How to delete Temporary Internet Files

AndreyDev

Hi Suman!

it's easy

Code Block

private ArrayList AllFiles;

private void ListFiles(string folder)

{

// Here we crate array of all dirs

System.IO.DirectoryInfo [] dirs=new System.IO.DirectoryInfo(folder).GetDirectories();

// Here we crate array of all files

System.IO.FileInfo [] files=new System.IO.DirectoryInfo(folder).GetFiles();

// Here we list the files

foreach(System.IO.FileInfo file in files)

{

//MessageBox.Show(file.FullName);

// here we out filename without root path

this.AllFiles.Add(file.FullName);

}

// here we search files in subfolders (using recursive method)

foreach (System.IO.DirectoryInfo dir in dirs)

{

ListFiles(dir.FullName);

}

}

and how to use it

Code Block

private void button4_Click(object sender, System.EventArgs e)

{

AllFiles= new ArrayList();

ListFiles(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache));

// here we write elements in our array

foreach(string fname in AllFiles)

{

// or you can write a code for delete file like you already did it.

//

// FileInfo f = new FileInfo(fname);

// f.Delete();

//

this.richTextBox1.Text+=fname+'\r';

}

}

Regards,

Andrey.






Re: Internet Explorer Extension Development How to delete Temporary Internet Files

sumannm

Hi Andrey,

Code you have provided, helped me in solving the problem.

THANK YOU for your support.

Regards,

Suman.N.M