Favorites in webbrowser help!!???

ok im making a internet browser

and i added the addtofavorites option and a favorites drop downlist

these are the codes im useing

Private Sub Favorites_DropDownItemClicked(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles Favorites.DropDownItemClicked

WebBrowser1.Navigate(e.ClickedItem.Text)

End Sub

Private Sub AddToFavorites_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddToFavorites.Click

Favorites.DropDownItems.Add(WebBrowser1.Url.ToString)

End Sub

and when i add a favorite it gos right and everything but when i close the app and reopen all my favorites are gone

how do i get it to were the favorites get saved



Answer this question

Favorites in webbrowser help!!???

  • rolandpish

    everything, the entire solution/project zipped up and emailed to me (email addy in profile)

  • Raoul_BennetH

    well what all code do you need
  • Cannan

    read through the links I supplied. Even more examples about xml serialization:

    http://msdn2.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx

    http://msdn2.microsoft.com/en-us/library/bdxxw552.aspx

    http://msdn2.microsoft.com/en-us/library/dsh84875.aspx

    basically, it helps us to store objects into a file which we can restore back easily instead of having to write down each line of links into a text file then reading them back again - Xml Serialization does this for us with the ability to store objects and its properties.

    It will be hard to grasp but its worth it and you would gain more knowledge!



  • David Luu

    send over the code and ill see what I can do, email address in profile and ill also be sure to post here the solution (basically converting the links supplied into VB.NET)

  • vbjunkie

    ok yea good point on that one

    yea i will zipp it up and send it then


  • SeanC

    it's because you need some way of storing the values/favourites - your application needs to have this functionality. Either save it to an app settings configuration file or maybe use another method, such as serializing to xml file and then deserialize when your app is going to be starting up again to restore those values.

    There have been a few posts about this, and I have made one in C# but not VB.NET

    Here is an example you could follow about how to create a favorites object and serialize/deserialize the object - basically change it to your needs.

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=743715&SiteID=1

    even though this is C#, you maybe able to figure out what's going on or follow the logic:

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=801237&SiteID=1

    I hope this gets you started, but DO post back if you have questions ;-)



  • John Dunn

    well because this is a community and in order to help you some things needed to be seen in its full and besides I wouldn't want the program if I could create my own :-) but if you don't want to then that's fine but would suggest following the links supplied

  • ahmad.nazmi

    um yea i kinda get what you mean by the xml thing but still dont understand how i would make the code for it

    sorry if im asking all the beginner questions but i just started this and its my very first program


  • yhong

    ok i sent it

    its a pretty basic program


  • wirol

    well i figured it would be the perfect type of program for my first one

    well i stiill havnt figured out how to get them to save

    and its making me mad

    im not the reading type i need to be showed sometimes

    so if this is not to much to ask could someone make the code for me

    i posted what im using to access the urls and what im adding them with but i just cant doit alone


  • War_Child

    I've just zipped off the solution to the OP. Here is the code converted from C# to VB.NET from the links supplied earlier. Please also follow them as they tell you what other events you should implement for the toolstripmenuitems.


    Imports System.Xml

    Imports System.Xml.Serialization

    Imports System.IO

    Imports System.Collections

    Imports System.Collections.Generic

    Public Class Favourite

    Private theDisplayName As String = String.Empty
    Private theLink As String = String.Empty
    Private theFavourites As New List(Of Favourite)

    Public ReadOnly Property TheFavouriteCollection() As List(Of Favourite)
    Get

    Return Me.theFavourites
    End Get

    End Property

    Public Property TheURL() As String

    Get

    Return Me.theLink
    End Get

    Set(ByVal value As String)
    Me.theLink = value
    End Set

    End Property

    Public Property TheUrlDescription() As String

    Get

    Return Me.theDisplayName
    End Get

    Set(ByVal value As String)
    Me.theDisplayName = value
    End Set

    End Property

    Public Sub New(ByVal displayName As String, ByVal url As String)
    Me.theDisplayName = displayName
    Me.theLink = url
    End Sub

    Public Sub New()
    End Sub

    Public Overloads Sub Favourite()
    End Sub



    Public Sub DoAddFavourite(ByVal theNewFav As Favourite)
    Me.theFavourites.Add(theNewFav)
    End Sub

    Public Shared Function DoLoadFavourites() As Favourite
    If File.Exists(Application.StartupPath & "\theFavouritesSaved.xml") Then

    Dim theTypes(0) As Type
    theTypes(0) =
    GetType(List(Of Favourite))

    Try

    Dim theDeSerializer As New XmlSerializer(GetType(Favourite), theTypes)
    Dim theReader As New StreamReader(Application.StartupPath & "\theFavouritesSaved.xml")
    Dim theFavourites As Favourite = theDeSerializer.Deserialize(theReader)
    theReader.Close()
    Return theFavourites
    Catch ex As Exception
    Return Nothing

    End Try

    End If

    End Function

    Public Function DoSaveFavourites() As Boolean

    Dim theTypes(0) As Type
    theTypes(0) =
    GetType(List(Of Favourite))

    Try

    Dim theSerializer As New XmlSerializer(GetType(Favourite), theTypes)
    Dim theWriter As New StreamWriter(Application.StartupPath & "\theFavouritesSaved.xml")
    theSerializer.Serialize(theWriter,
    Me)
    theWriter.Close()
    Return True

    Catch ex As Exception
    Return False

    End Try

    End Function
    End
    Class


    In your main form, declare globally:

    private theFavourites as Favourites()

    form_load, we want to load the favourites:


    If Me.theFavourites Is Nothing = True Then

    Me.theFavourites = New Favourite()
    End If

    Me.theFavourites.TheFavouriteCollection.Clear()
    FavToolStripMenuItem.DropDown.Items.Clear()
    Me.theFavourites = Favourite.DoLoadFavourites()

    If Me.theFavourites Is Nothing = False Then

    For Each currentFav As Favourite In Me.theFavourites.TheFavouriteCollection
    Me.FavToolStripMenuItem.DropDown.Items.Add(currentFav.TheUrlDescription)
    Me.FavToolStripMenuItem.DropDown.Items(Me.FavToolStripMenuItem.DropDown.Items.Count - 1).ToolTipText = currentFav.TheURL
    Next
    End If


    Whenever we add a new favourite:


    Dim theNewFav As New Favourite("Description", "URL")

    If Me.theFavourites Is Nothing Then

    Me.theFavourites = New Favourite()
    End If

    Me.theFavourites.DoAddFavourite(theNewFav)
    Me.FavToolStripMenuItem.DropDown.Items.Add(theNewFav.TheUrlDescription)
    Me.FavToolStripMenuItem.DropDown.Items(Me.FavToolStripMenuItem.DropDown.Items.Count - 1).ToolTipText = theNewFav.TheURL


    If Me.theFavourites.DoSaveFavourites() = False Then

    MessageBox.Show("Could not save favourites")
    End If

    When we want to save the entire favourites:



    If Me.theFavourites.DoSaveFavourites() = False Then

    MessageBox.Show("Could not save favourites")
    End If

    The whole idea is to make an object called favourites with 2 properties:

  • The description (display name)

  • the url to navigate to

    so when we add a favourite, we create a new fav object, set its properties, then add it to the favourites collection and serialize it (store it to file)

    When we load the favourites, we deserialize it, restoring back the favourites saved from last time, back into memory



  • Kevin Hoffman

    how do i know you wont just take my program
  • Robert3234

    Settings is what you need!

    go to www.gameuniv.net.

    I am teaching a Visual Basic class there. It is called Visual Basic 2005. Join it.

    then, one you learn how to add "settings," put that code into the event.


  • ArunSingh

    I am curious.

    Other than for the fun of it, why do you want to make an internet browser

    Do you know that you can use the Internet Explorer class (SHDocVw.InternetExplorer)

    and you will have all the functionality, including favourites etc.


  • Favorites in webbrowser help!!???