Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Clearing cache in a webbrowser control.

101 views
Skip to first unread message

jbc

unread,
Jan 8, 2007, 9:07:54 PM1/8/07
to
Hi, I am trying to programmatically clear the WebBrowser cache in my
VB.net from and I am having trouble with it. It is getting stuck at the
FindFirstUrlCacheEntry and I don't know why it is not working. Can
anyone help me on this? TIA!


Private Declare Function FindFirstUrlCacheGroup Lib "wininet.dll" ( _
ByVal dwFlags As Integer, _
ByVal dwFilter As Integer, _
ByVal lpSearchCondition As Integer, _
ByVal dwSearchCondition As Integer, _
ByRef lpGroupId As Date, _
ByVal lpReserved As Integer) As Integer

Private Declare Function FindNextUrlCacheGroup Lib "wininet.dll" (
_
ByVal hFind As Integer, _
ByRef lpGroupId As Date, _
ByVal lpReserved As Integer) As Integer

Private Declare Function DeleteUrlCacheGroup Lib "wininet.dll" ( _
ByVal sGroupID As Date, _
ByVal dwFlags As Integer, _
ByVal lpReserved As Integer) As Integer


Private Declare Function FindFirstUrlCacheEntry Lib "wininet.dll"
Alias "FindFirstUrlCacheEntryA" ( _
ByVal lpszUrlSearchPattern As String, _
ByRef lpFirstCacheEntryInfo As INTERNET_CACHE_ENTRY_INFO, _
ByVal lpdwFirstCacheEntryInfoBufferSize As Integer) As Integer

Private Declare Function FindNextUrlCacheEntry Lib "wininet.dll"
Alias "FindNextUrlCacheEntryA" ( _
ByVal hEnumHandle As Integer, _
ByRef lpNextCacheEntryInfo As INTERNET_CACHE_ENTRY_INFO, _
ByRef lpdwNextCacheEntryInfoBufferSize As Integer) As Integer

Private Declare Function DeleteUrlCacheEntry Lib "wininet.dll"
Alias "DeleteUrlCacheEntryA" ( _
ByVal lpszUrlName As Integer) As Integer

Private Structure INTERNET_CACHE_ENTRY_INFO
Dim dwStructSize As Integer
Dim szRestOfData() As Integer
End Structure

Private Const CACHGROUP_SEARCH_ALL As Integer = &H0
Private Const ERROR_NO_MORE_FILES As Integer = 18
Private Const ERROR_NO_MORE_ITEMS As Integer = 259
Private Const CACHEGROUP_FLAG_FLUSHURL_ONDELETE As Integer = &H2
Private Const BUFFERSIZE As Integer = 2048

Private Sub clearCache()
Dim sGroupID As Date
Dim hGroup As Integer
Dim hFile As Integer
Dim sEntryInfo As New INTERNET_CACHE_ENTRY_INFO
Dim iSize As Integer

On Error Resume Next

' Delete the groups
hGroup = FindFirstUrlCacheGroup(0, CACHGROUP_SEARCH_ALL,
Nothing, 0, sGroupID, Nothing)

' To avoid error using it with IE4 as FindFirstUrlCacheGroup is
not implemented
If Err.Number <> 453 Then
If (hGroup = 0) And (Err.LastDllError <> 2) Then
Trace.TraceError("An error occurred enumerating the
cache groups: " & Err.LastDllError)
Exit Sub
End If
Else
Err.Clear()
End If

If (hGroup <> 0) Then
'We succeeded in finding the first cache group.. enumerate
and delete
Do
If (0 = DeleteUrlCacheGroup(sGroupID,
CACHEGROUP_FLAG_FLUSHURL_ONDELETE, Nothing)) Then
' To avoid error using it with IE4 as
FindFirstUrlCacheGroup is not implemented
If Err.Number <> 453 Then
Trace.TraceError("Error deleting cache group: "
& Err.LastDllError)
Exit Sub
Else
Err.Clear()
End If
End If
If (0 = FindNextUrlCacheGroup(hGroup, sGroupID,
Nothing)) And (Err.LastDllError <> 2) Then
Trace.TraceError("Error finding next url cache
group: " & Err.LastDllError)
End If
Loop Until Err.LastDllError = 2
End If

' Delete the files
sEntryInfo.dwStructSize = 80
'sEntryInfo.szRestOfData =
Array.CreateInstance(GetType(System.Int32), 1024)
iSize = 0 'BUFFERSIZE
hFile = FindFirstUrlCacheEntry(Nothing, sEntryInfo, iSize)
If (hFile = 0) Then
If (Err.LastDllError = ERROR_NO_MORE_ITEMS) Then
GoTo done
End If
Trace.TraceError("Error: FindFirstUrlCacheEntry - " &
Err.LastDllError)
Exit Sub
End If
Do
If (0 = DeleteUrlCacheEntry(sEntryInfo.szRestOfData(0)))
And (Err.LastDllError <> 2) Then
Err.Clear()
End If
iSize = BUFFERSIZE
If (0 = FindNextUrlCacheEntry(hFile, sEntryInfo, iSize))
And (Err.LastDllError <> ERROR_NO_MORE_ITEMS) Then
Trace.TraceError("Error: Unable to find the next cache
entry - " & Err.LastDllError)
Exit Sub
End If
Loop Until Err.LastDllError = ERROR_NO_MORE_ITEMS
done:
Trace.TraceInformation("Cache cleared.")
End Sub

0 new messages