Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am working a project and want to save Listbox Data into a Text File.but for this i have no Mind.please help me .
I have a Listbox with Items.I want to save all items into a text file.
Thanks
Posted
Updated 14-Aug-13 18:48pm
v2
Comments
CodeBlack 15-Aug-13 0:43am    
can you please explain more about the actual requirement ?

1 solution

Try something like..
VB
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)

Or,
VB
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
 
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