Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3501316
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:50:38+00:00 2026-05-18T12:50:38+00:00

I have added an object called fixture to a listbox. I look in a

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T12:50:38+00:00Added an answer on May 18, 2026 at 12:50 pm

    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.

    public class XmlFileInfo
    {
        public XmlFileInfo(string fixture, string path)
        {
            Fixture = fixture;
            Path = path;
        }
        public string Fixture { get; set; }
        public string Path { get; set; }
    }
    

    Then create an ObservableCollection with XmlFileInfo and bind your ListBox to that collection like this

    <ListBox Name="lbxLibrary"
             ItemsSource="{Binding XmlFileInfoCollection}"
             DisplayMemberPath="Fixture"
             SelectionChanged="lbxLibrary_SelectionChanged"/>
    

    Example of how code behind could look

    public MainWindow()
    {
        InitializeComponent();
        XmlFileInfoCollection = new ObservableCollection<XmlFileInfo>();
        this.DataContext = this;
    }
    public ObservableCollection<XmlFileInfo> XmlFileInfoCollection
    {
        get;
        private set;
    }
    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        CreateLibrary();
    }
    public void CreateLibrary()
    {
        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);
            XmlFileInfo xmlFileInfo = new XmlFileInfo(fixture, dir);
            XmlFileInfoCollection.Add(xmlFileInfo);
        }
    }
    

    And in some event, say SelectionChanged, you can easily find the URL for the selected item like this

    private void lbxLibrary_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        XmlFileInfo xmlFileInfo = lbxLibrary.SelectedItem as XmlFileInfo;
        string path = xmlFileInfo.Path;
        // ...
    }
    

    Update

    Uploaded sample project here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XmlSerializer object, and I have added 2 event handlers to the
I have an object that I added to a few different ArrayLists. I wanna
I have a custom object called Technology__c and join object called AccountTechnologies which is
I have quite a simple situation. I've got 3 objects: an object called TrainingConsultant
I'm trying to call web service for few hours. I have added clientaccesspolicy.xml: <?xml
I have added: sub1_btn Within sub1_btn there is a movieclip called arrow. Using this
I have downloaded and added apples reachability(.h+.m) files to my view bases project and
I have added three methods with parameters: public static void doSomething(Object obj) { System.out.println(Object
I have an EF object called PagePreference. The corresponding table contains three fields: UserName(PK,
In short, I have an object called PersonList that has a List of Person

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.