Results 1 to 7 of 7

Thread: [2005] Saving this items

  1. #1

    Thread Starter
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    [2005] Saving this items

    Hi to all,

    im creating a webbrowser, with a favorites function using a listbox and a bindingsource and this is how i did it :

    with help of this forum i created a sort of custom object, ill post it here :

    Vb .net Code:
    1. Public Class Favorites
    2.     Private _title As String
    3.     Private _url As String
    4.     Public Property Title() As String
    5.         Get
    6.             Return Me._title
    7.         End Get
    8.         Set(ByVal value As String)
    9.             Me._title = value
    10.         End Set
    11.     End Property
    12.     Public Property Url() As String
    13.         Get
    14.             Return Me._url
    15.  
    16.         End Get
    17.         Set(ByVal value As String)
    18.             Me._url = value
    19.         End Set
    20.     End Property
    21.     Public Sub New(ByVal title As String, ByVal url As String)
    22.         Me._title = title
    23.         Me._url = url
    24.     End Sub
    25.  
    26. End Class

    and the code i use to add new items to the listbox is this :
    add new item
    Vb .net Code:
    1. Dim N As Integer
    2.         N = Favs.FindStringExact(Applicationhelper _
    3.         .CurrentBrowser.DocumentTitle)
    4.         If (N = -1) Then
    5.             Me.Listoffavorites.Add(New Favorites(Applicationhelper _
    6.                                       .CurrentBrowser.DocumentTitle, Applicationhelper _
    7.                                       .CurrentBrowser.Url.ToString))
    8.         End If

    set the data to the listbox
    Vb .net Code:
    1. Dim Listoffavorites As New System.ComponentModel.BindingList(Of Favorites)
    2.  
    3.     Me.BindingSource1.DataSource = Me.Listoffavorites
    4.         Me.Favs.DisplayMember = "Title"
    5.         Me.Favs.ValueMember = "Url"
    6.         Me.Favs.DataSource = Me.BindingSource1

    well, now that i described what i have done ill tell u what i want to do
    i want to save those items in a textbox or in anyway, can anyone help me ?
    thanks
    C# and WPF developer
    My Website:
    http://singlebits.com/

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] Saving this items

    I don't know what you mean by saving them to a TextBox.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    Re: [2005] Saving this items

    sorry, i made a mistake i want to save them into a *TEXT FILE
    C# and WPF developer
    My Website:
    http://singlebits.com/

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] Saving this items

    Do you have a specific format in mind for this file? If not I'd suggest using XML. You can serialise a collection of your objects to a file in about four lines of code, then deserialise the file back to a collection in the same. Search the forum for XmlSerializer and you should find examples.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    Re: [2005] Saving this items

    ive been searching the forum for xmlSerializer examples, but there no thread that can help me, i tried this code but nothing happends....:

    to deserialize the file:
    Vb .net Code:
    1. Dim n As New Runtime.Serialization.Formatters.Binary.BinaryFormatter
    2.         Dim ss As New IO.FileStream("C:\Users\Pablo\Documents\set.bin", IO.FileMode.Open)
    3.  
    4.         listoffavorites = CType(n.Deserialize(ss), Global.System.ComponentModel.BindingList(Of Favorites))
    5.  
    6.         ss.Close()
    to sereliaze the file
    Vb .net Code:
    1. Dim s As New Runtime.Serialization.Formatters.Binary.BinaryFormatter
    2.         Dim n As New IO.FileStream("C:\Users\Pablo\Documents\set.bin", IO.FileMode.Create)
    3.         s.Serialize(n, listoffavorites)
    4.         n.Close()

    nothing happends while using this codes what i want to do its save all the favorites item that are currently in listoffavorites, and load them again at form load but i have no idea on how to do this, maybe its by xmlserializer but i dont know how to use this i searched in msdn but i found nothing, so i will really apreciate if someone help....thanxs
    C# and WPF developer
    My Website:
    http://singlebits.com/

  6. #6

    Thread Starter
    Hyperactive Member Pac_741's Avatar
    Join Date
    Jun 2007
    Location
    Mexico
    Posts
    298

    Re: [2005] Saving this items

    help
    C# and WPF developer
    My Website:
    http://singlebits.com/

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] Saving this items

    I just searched the VB.NET forum for xmlserializer and this was the second result, after this very thread. I'm guessing that's where you got that code from but at the end it has an example of using an XmlSerializer. You really didn't look very hard.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width