I have added an object called fixture to a listbox. I look in a directory and sub directories for all XML files. I then get the name of the files and all them to the list.
public void CreateLibrary()
{
List<string> fixtureList = new List<String>();
string[] dirs = Directory.GetFiles(@"C:\Windows.old\Users\Michael\Desktop\data\fixtures\", "*.xml",
SearchOption.AllDirectories);
foreach (string dir in dirs)
{
string fixture = System.IO.Path.GetFileName(dir);
lbxLibrary.Items.Add(fixture);
}
I would like to be able to get the file url from the currently selected item in the listbox. I am aware that I might need to change the way I am importing the files which is fine, but Im after some advice and some docs to read.
Cheers in advance 🙂
Michael.
Instead of adding strings directly to the ListBox I would suggest you create a class called something like XmlFileInfo where you store info for each of your loaded xml files.
Then create an ObservableCollection with XmlFileInfo and bind your ListBox to that collection like this
Example of how code behind could look
And in some event, say SelectionChanged, you can easily find the URL for the selected item like this
Update
Uploaded sample project here