Jordy1212
asked on
OpenFileDialog Help
Hi, I'm trying to make a media player in vb.net. What I'm having trouble with is selecting music to add to a listbox. What I've tried to do is:
Every time I added a song it added only 1 song saying System.String[] how do I fix this?
Help will be appreciated
OpenFileDialog1.Filter = "Audio Files (*.mp3)|*.mp3|" & "Audio Files (*wav)|*.wav|" & "All files|*.*"
OpenFileDialog1.InitialDirectory = System.Environment.CurrentDirectory
OpenFileDialog1.FilterIndex = 1
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
lstMusic.Items.Add(OpenFileDialog1.FileNames)
End If
Every time I added a song it added only 1 song saying System.String[] how do I fix this?
Help will be appreciated
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
OpenFileDialog1.FileNames is an array, you need to get the value of one element from the array. Or. you can use OpenFileDialog1.FileName, which contains only one file path.
You need to loop through the array to add the string value into the listbox one by one.
You need to loop through the array to add the string value into the listbox one by one.
OpenFileDialog1.FileNames is an array, you need to get a value of one element from the array using array index. Or. you can use OpenFileDialog1.FileName, which contains only one file path.
You need to loop through the array to add the string values into the listbox one by one.
You need to loop through the array to add the string values into the listbox one by one.
sorry, that was vb.net posted code. here is the c# equivalent
foreach (f in OpenFileDialog1.FileNames) {
lstMusic.Items.Add(f);
}
foreach (f in OpenFileDialog1.FileNames)
lstMusic.Items.Add(f);
}
Sorry for the redundant submit. Error happened and I thought it's not through.
ASKER
Thanks!
lstMusic.Items.Add(OpenFil
is referring to the list of filenames. It returns the string array
For a single file selection drop the s
lstMusic.Items.Add(OpenFil