Question listbox items file path/name

hema-1

New member
Joined
May 14, 2013
Messages
1
Programming Experience
Beginner
im trying to make mp3 player using listbox named "playlist" contains items opened by openfiledialouge named "ofd" and windowsmediaplayer named wmp.

the problem is that playlist items must have the full path to run using the code
For Each track As String In ofd.FileNames

VB.NET:
Private Sub ofd_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ofd.FileOk
        If Button6.Text = "Open" Then
            For Each track As String In ofd.FileNames
                playlist.Items.Add(track)
            Next
            playlist.SelectedIndex = 0
            wmp.URL = playlist.SelectedItem
            Button2.Enabled = True
            btnn.Enabled = True
            btnb.Enabled = True
            Button3.Enabled = True
            Button3.Text = "Pause"
            Button6.Text = "Add"
        ElseIf Button6.Text = "Add" Then
            For Each track As String In ofd.FileNames
                playlist.Items.Add(track)
            Next
        End If

the line
VB.NET:
For Each track As String In ofd.SafeFileNames

make a good result as i want but the wmp doesn't work with it


here is my img
Mp3.gif
 
Last edited:
If the files are all in same folder you can just store the folder name somewhere and use it later when you need the full path. IO.Path class has members useful for retrieving the folder and file name from path, and combine them later.
If not you could add FileInfo objects to the ListBox.Items and set ListBox.DisplayMember to display the "Name" property. Later you retrieve the item as FileInfo and use its FullName property.
 
Back
Top