I am brand new to Visual Studio so please forgive my current lack of knowledge but I've tried searching everywhere for this and am relatively surprised that I couldn't find something about this elsewhere. I am using a currently using an Openfiledialogue with multi-file selection allowed. It then adds the files into a ListBox. I plan on eventually switching to going with FolderBrowserDialogue but that should not change what I am trying to find out now.
I use SafeFileNames (as shown below) to print only the filename and file extension to the listbox as using FileNames looked horrible in the list box as it included the path to the file. So this makes the list of files (Videos in this case) much more compact and neater. However, what I am creating is supposed to allow you to play the file that you have selected in the listbox but I cannot get it to do so with SafeFileNames because the selected item no longer 'sends' the location (in this case path location) to the player. So now my files will not play.
Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click OpenFileDialog1.ShowDialog() If Windows.Forms.DialogResult.OK Then For Each track As String In OpenFileDialog1.SafeFileNames ListBox1.Items.Add(track) Next End If End Sub
The result of FileNames would be like:
The result of SafeFileNames:
SafeFileNames makes the list look exactly how I want it to (meaning that I don't need a really long list box for a user to be able to the actual file after the path) but then the control doesn't know the location of the file with that name.
Private Sub button2_Click(sender As Object, e As EventArgs) Handles button2.Click AxWindowsMediaPlayer1.URL = listbox1.SelectedItem End Sub
I was thinking of appending the path to the filename and extension that end up getting sent to the "play" button which tells WMP to play the selected file. But with the videos potentially residing in many different folders all over a user's computer, I am not sure that would work so well.
If anyone has any ideas as to how, after a user has added files from different folders on their system, that the listbox will still show only the filename and extension but the button 2 code (for the Start) button will know the location of the file to be played...I would be ever so grateful!