Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a strange problem with the .Net WebBrowser control. I'm trying to delete facebook cookies and then dispose the WebBrowser control so that the cookies might be released from the memory and then reinitialize the WebBrowser control again in order for them to relogin to facebook.

It's not working. If I close the app and do that, it works.

Here's the code (yes, it doesn't look preety) I'm using:

VB
Private Sub ReinitializeBrowser()
        '_instance = New FrmBrowser()
        Dim uri As System.Uri = WebBrowser1.Url
        Dim point As Point = WebBrowser1.Location
        Dim size As Size = WebBrowser1.Size
        If Not (Me.WebBrowser1 Is Nothing) Then
            Me.WebBrowser1.Dispose()
            Me.Controls.Remove(Me.WebBrowser1)
        End If
        WebBrowser1 = New System.Windows.Forms.WebBrowser
        Me.WebBrowser1.Location = point
        Me.WebBrowser1.MinimumSize = New System.Drawing.Size(20, 20)
        Me.WebBrowser1.Name = "WebBrowser1"
        Me.WebBrowser1.ScrollBarsEnabled = False
        Me.WebBrowser1.Size = size
        Me.WebBrowser1.TabIndex = 2
        AddHandler Me.WebBrowser1.Navigating, AddressOf WebBrowser1_Navigating
        AddHandler Me.WebBrowser1.NewWindow, AddressOf WebBrowser1_NewWindow
        Me.Controls.Add(Me.WebBrowser1)
        Browse(strURL)
    End Sub

VB
Public Function ResetBrowser() As Boolean
        Dim IsFBCookieDeleted As Boolean = False
        Dim theCookies() As String = System.IO.Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.Cookies))
        For Each currentFile As String In theCookies
            Try
                If (currentFile.ToString.Contains("@facebook")) Then
                    IsFBCookieDeleted = True
                    System.IO.File.Delete(currentFile)
                End If
            Catch ex As Exception
            End Try
        Next
        If (IsFBCookieDeleted) Then
            FrmBrowser.Instance.ReinitializeBrowser()
            Return True
        Else
            Return False
        End If
    End Function


Any help would be really appreciated.

Thanks,

Sudeep
Posted
Updated 2-Dec-10 7:05am
v2

1 solution

For starters, try seeing if you are getting exceptions when deleting the files. My guess is that you may be experiencing this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900