hi vbforums
how do i save everything thats in a listbox and save dialog shows exatensions like .txt .text .html .htm .url types and it writes to where you save it too also check path files would be awesome
thanks
Printable View
hi vbforums
how do i save everything thats in a listbox and save dialog shows exatensions like .txt .text .html .htm .url types and it writes to where you save it too also check path files would be awesome
thanks
There's a couple of separate, basically independent questions in there. Saving data from a listBox to a file is the same whether you use a SaveFileDialog or not. Using a SaveFileDialog is the same no matter what you're saving. This is an example of where you should break the problem down into its components. Understand the components independently and then you can use them anywhere, independent of each other.
So, to the SaveFileDialog first. Create an instance, set its properties appropriately and then call ShowDialog. If that returns OK then the user clicked OK and you get the selected file from the FileName property. Simple. If you want to know what properties to set you should read the MSDN documentation to see what properties it has and what each one is for.
As for saving the contents of a ListBox, it depends on what the items are and how you want to save them. I'll assume that the items are Strings and you want to save each to a line in a text file. In that case, you'd create a StreamWriter and then use a For Each loop to enumerate the items, calling WriteLine for each one.
yea its a list box full of numbers and letters here is the code i got to far but it doesnt save
Dim myFileDialog As SaveFileDialog = New SaveFileDialog()
With myFileDialog
.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
.FilterIndex = 1
.InitialDirectory = "C:\"
.Title = "Save File"
.CheckFileExists = False
End With
If myFileDialog.ShowDialog() = DialogResult.OK Then
RandomPassAndNumberListBox.Text.ToString()
Console.WriteLine(myFileDialog.FileName)
End If
myFileDialog = Nothing
End Sub
It doesn't save because you have no code to save. Did you read the last paragraph of my previous post?
i did but im still on my first application teaching me self but didnt understand what you wanted me 2 do
Step 1Step 2Quote:
Originally Posted by jmcilhinney
Step 3Quote:
Originally Posted by jmcilhinney
You don't have to worry about step 2 and step 3 until you've completed step 1. So, create a StreamWriter. If you don't know how to create a StreamWriter then you should either read the documentation or look for examples.Quote:
Originally Posted by jmcilhinney
http://www.google.com.au/search?q=cr...ient=firefox-a
As you can see, there is plenty of information available.
This code:
Code:Dim i As Integer
Dim wsw As IO.StreamWriter
SaveFileDialog2.Title = "Save Games List"
SaveFileDialog2.DefaultExt = ".txt"
SaveFileDialog2.FileName = "Have List"
SaveFileDialog2.ShowDialog()
wsw = New IO.StreamWriter(SaveFileDialog2.FileName)
For i = 0 To RandomPassAndNumberListBox.Items.Count - 1
wsw.WriteLine(RandomPassAndNumberListBox.Items.Item(i))
Next
wsw.Close()
Should do it, it prompts the user to choose a location and file name, then saves a .txt file containing a list of all the items in the listbox. Attach it to a click event etc (like on a button) and then test it out.
thank you dude