chuckalicious
asked on
Clearing IE Cache using VB.NET
Deleting Internet Explorer Cache using VB.Net
I need to be able to clear the IE cache using VB.Net.
I currently have a simple app that does a few things with a new IE window, created using:
CreateObject("InternetExpl orer.Appli cation")
Any help greatly appreciated
I need to be able to clear the IE cache using VB.Net.
I currently have a simple app that does a few things with a new IE window, created using:
CreateObject("InternetExpl
Any help greatly appreciated
Here's some code that will get the History folder via the .NET SpecialFolders, and then get files within that for deletion. Essentially, you want to get rid of everything within that special folder. Some may not be accessible if they are in use though.
private void frmMain_Load(object sender, System.EventArgs e)
{
path = Environment.GetFolderPath( Environmen t.SpecialF older.Hist ory) + "\\";
getList(path);
}
private void getList(string thepath)
{
DirectoryInfo dir = new DirectoryInfo(thepath);
DirectoryInfo[] dirs = dir.GetDirectories();
FileInfo[] files = dir.GetFiles();
foreach(DirectoryInfo d in dirs)
{
getList(d.FullName);
}
foreach(FileInfo f in files)
{
lstHistory.Items.Add(f.Ful lName);
}
}
private void clrHist()
{
for(int i = 0; i < lstHistory.Items.Count; i++)
{
try
{
File.Delete(lstHistory.Ite ms[i].Text );
}
catch(IOException e)
{
MessageBox.Show("Error: \n\n\n" + e.Message);
}
}
}
private void frmMain_Load(object sender, System.EventArgs e)
{
path = Environment.GetFolderPath(
getList(path);
}
private void getList(string thepath)
{
DirectoryInfo dir = new DirectoryInfo(thepath);
DirectoryInfo[] dirs = dir.GetDirectories();
FileInfo[] files = dir.GetFiles();
foreach(DirectoryInfo d in dirs)
{
getList(d.FullName);
}
foreach(FileInfo f in files)
{
lstHistory.Items.Add(f.Ful
}
}
private void clrHist()
{
for(int i = 0; i < lstHistory.Items.Count; i++)
{
try
{
File.Delete(lstHistory.Ite
}
catch(IOException e)
{
MessageBox.Show("Error: \n\n\n" + e.Message);
}
}
}
ASKER
jimstar,
I've pasted that code into MS VB 2005 Basic Edition and it's just throwing up lots of errors about end of statements exptected and delcations expected. Should this code work in 2005 Basic Edition?
Note I'm very new to VB so the above might be a stupid question!
I've pasted that code into MS VB 2005 Basic Edition and it's just throwing up lots of errors about end of statements exptected and delcations expected. Should this code work in 2005 Basic Edition?
Note I'm very new to VB so the above might be a stupid question!
Oops, sorry! That is C# code. I'll see if I can convert it over, though it's been a while since I've done VB.NET. :)
I found an article that gives VB.NET code for clearing the IE cache, written by Microsoft Support. Give this a try:
http://support.microsoft.com/kb/262110/EN-US/
http://support.microsoft.com/kb/262110/EN-US/
ASKER
THanks JimStar
When I paste that code in, it tells me that VB no longer supports Type and I should use Structure instead and that the variables aren't declared.
So I go from this:
Private Type INTERNET_CACHE_ENTRY_INFO
dwStructSize As Long
szRestOfData(1024) As Long
End Type
to this:
Private Structure INTERNET_CACHE_ENTRY_INFO
Dim dwStructSize As Long
Dim szRestOfData(1024) As Long
End Structure
I then get the error of "Arrays declared as structure members cannot be declared with an initial size" for the line Dim szRestOfData(1024) As Long
I have no idea what this means :(
When I paste that code in, it tells me that VB no longer supports Type and I should use Structure instead and that the variables aren't declared.
So I go from this:
Private Type INTERNET_CACHE_ENTRY_INFO
dwStructSize As Long
szRestOfData(1024) As Long
End Type
to this:
Private Structure INTERNET_CACHE_ENTRY_INFO
Dim dwStructSize As Long
Dim szRestOfData(1024) As Long
End Structure
I then get the error of "Arrays declared as structure members cannot be declared with an initial size" for the line Dim szRestOfData(1024) As Long
I have no idea what this means :(
ASKER
JimStar, the code you posted in C# seems a lot more straight forward than the code in the link you provided, which is erroring with something about an unbalanced stack.....
Would it be possible for you to convert it from C# to vb.net?
Thanks
Would it be possible for you to convert it from C# to vb.net?
Thanks
It was actually an error on my part - I converted it already, but the code didn't work. Deleting the files is not possible because explorer.exe has them open all the time.
The only option appears to be using the functions that are specifically designed for clearing the cache.
I'm working on a solution right now. The problem is that older versions of VB use Long, and newer versions need to use Integer to pass information around. There are a few issues with the code on Microsoft's site that I am trying to correct.
The only option appears to be using the functions that are specifically designed for clearing the cache.
I'm working on a solution right now. The problem is that older versions of VB use Long, and newer versions need to use Integer to pass information around. There are a few issues with the code on Microsoft's site that I am trying to correct.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Depending on your specific project, you may need to rename Sub Main() to a different name that you call when you want to clear the cache.
Let me know if you have any trouble.
Let me know if you have any trouble.
ASKER
Thanks. A few things with that. According to my VB Studio, instead of Imports System.Runtime.InteropServ ices we should be using Imports System.Runtime.InteropServ ices.ComTy pes.FILETI ME
and also it wants the variables Marshal and DllImport declared. What should I declare them as?
Thanks again
and also it wants the variables Marshal and DllImport declared. What should I declare them as?
Thanks again
Marshal and DllImport are under System.Runtime.InteropServ ices, which is why it gets imported. When you changed it to ... ComTypes.FILETIME, it made it so that the Marchal and DllImport couldn't be found.
What specifically is the error you get when you just use:
Imports System.Runtime.InteropServ ices
?
What specifically is the error you get when you just use:
Imports System.Runtime.InteropServ
?
One option that should fix any issue with Marshal and DllImport would be to prepend the System.Runtime.InteropServ ices string to them.
So, wherever you see:
Marshal
Make it:
System.Runtime.InteropServ ices.Marsh al
... and the same with DllImport.
It's odd that you're getting issues with the general import, but the above tip should fix any problem.
So, wherever you see:
Marshal
Make it:
System.Runtime.InteropServ
... and the same with DllImport.
It's odd that you're getting issues with the general import, but the above tip should fix any problem.
ASKER
Ok no errors, now, the last question :) How do I call this? My code is being run via a button on a form.
Thanks
Thanks
To call it from a form, you'll want to rename Sub Main() in Module1 to something like Sub ClearCacheNow(). Then, you should be able to double click on the button on your form, and then type ClearCacheNow() in the button's subroutine.
ASKER
Alright, one last question, does this clear just the cache, or does it clear cookies and completed form information as well?
This code clears everything.
I should clarify - it clears "Temporary Internet Files", which contains cached files and cookie information. I don't believe it includes the autocomplete data, typed URLs, or history.
http://dotnetslackers.com/ASP_NET/re-14845_Extending_the_ASP_NET_Cache_Object_Cache_Clear.aspx