Question how to save ListBox items?

xxn5

Member
Joined
Oct 23, 2013
Messages
8
Programming Experience
1-3
how to save ListBox in vb.net
Dim files() As String
files = Directory.GetFiles("C:\", "*.mp3")

Dim file As String
For Each file In files
ListBox1.Items.Add(Path.GetFileName(file))
Next

output :
00001.mp3
00003.mp3
00005.mp3 ....

want to save all item wth Only filenam to another folder.
 
how to save ListBox in vb.net
Dim files() As String
files = Directory.GetFiles("C:\", "*.mp3")

Dim file As String
For Each file In files
ListBox1.Items.Add(Path.GetFileName(file))
Next

output :
00001.mp3
00003.mp3
00005.mp3 ....

want to save all item wth Only filenam to another folder.

VB.NET:
Dim mydocpath As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Dim sb As StringBuilder = New StringBuilder()

        For Each item In ListBox1.Items
            sb.AppendLine(item)
        Next

        Using outfile As StreamWriter = New StreamWriter(mydocpath + "\UserInputFile.txt", True)
            outfile.Write(sb.ToString())
        End Using
 
VB.NET:
Dim mydocpath As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Dim sb As StringBuilder = New StringBuilder()

        For Each item In ListBox1.Items
            sb.AppendLine(item)
        Next

        Using outfile As StreamWriter = New StreamWriter(mydocpath + "\UserInputFile.txt", True)
            outfile.Write(sb.ToString())
        End Using

thank but it only save list of item in
UserInputFile.txt

want to copy
00001.mp3

00003.mp3

00005.mp3 to another folder.
 
The File.Move method will move a file from one location to another. That can change the folder, the file name or both. You have to know the full path of both the source and destination when you call it. If you have multiple files to move then you call it multiple times, perhaps in a loop.
 
The File.Move method will move a file from one location to another. That can change the folder, the file name or both. You have to know the full path of both the source and destination when you call it. If you have multiple files to move then you call it multiple times, perhaps in a loop.

could you post an example.

You have to know the full path of both the source and destination
ListBox1 has file with only file nam.
 
could you post an example.
What do you not understand about the examples you found when you made the effort to search for yourself?
ListBox1 has file with only file nam.
I repeat: you need to know the full path of both the source and destination. If you don't provide a path then the current directory of the program will be assumed. If you don't want to use the current directory then you have to specify the path. If the ListBox doesn't contain the path then it should be obvious that you you need to store the path elsewhere. That said, if you were to use FileInfo objects and bind the list to the ListBox then you can display the Name property but you still have the FullName property for the full path.
 
Back
Top