Save ListBox To Text File


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Save ListBox To Text File

Hybrid View

  1. #1
    Join Date
    Dec 2007
    Posts
    10

    Save ListBox To Text File

    VB.NET 2005

    How would I save the contents of a ListBox to a text file?

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Code:
            Dim FileNumber As Integer = FreeFile()
            FileOpen(FileNumber, "d:\path\filename.txt", OpenMode.Output)
            For Each Item As Object In ListBox1.Items
                PrintLine(FileNumber, Item.ToString)
            Next
            FileClose(FileNumber)
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Also,
    Code:
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
       Using SW As New IO.StreamWriter("d:\ListBox1.txt", True)
         For Each itm As String In Me.ListBox1.Items
             SW.WriteLine(itm)
         Next
    End Using
    End Sub
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

Similar Threads

  1. Replies: 6
    Last Post: 08-16-2006, 11:32 PM
  2. Script for scrolling
    By Mark in forum Web
    Replies: 3
    Last Post: 08-30-2001, 12:45 PM
  3. Replies: 3
    Last Post: 08-23-2001, 12:01 PM
  4. Replies: 2
    Last Post: 05-31-2000, 11:11 AM
  5. Replies: 0
    Last Post: 04-17-2000, 02:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center