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 7914727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:12:48+00:00 2026-06-03T14:12:48+00:00

I have a ListBox & it has some files. I have 2 Panels in

  • 0

I have a ListBox & it has some files. I have 2 Panels in the same form & each Panel has many Labels which are corresponding tags of the loaded file in the ListBox.

Whenever the user selects each file then display the corresponding data of the selected file in the panel.

For an example this is one of the file content:

  <connection>
    <sourceId>sdfsdf</sourceId>
    <description>test.sdfds.interact.loop.com</description>
    <uri>https://test.sdf.interact.loop.com/WITSML/Store/Store.asmx</uri>
    <username>sdfdsf</username>
    <organizationFilter>*</organizationFilter>
    <fieldFilter>*</fieldFilter>
  </connection>

The listBox 1:

private void Form1_Load(object sender, EventArgs e)
        {
            PopulateListBox(listbox1, @"C:\TestLoadFiles", "*.rtld");

        }

private void PopulateListBox(ListBox lsb, string Folder, string FileType)
        {
            DirectoryInfo dinfo = new DirectoryInfo(Folder);
            FileInfo[] Files = dinfo.GetFiles(FileType);
            foreach (FileInfo file in Files)
            {
                lsb.Items.Add(file.Name);
            }
        }

How can I read and display data? Some one please explain to me how can I read/parse xml files in a directory and display data????

  • 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-06-03T14:12:50+00:00Added an answer on June 3, 2026 at 2:12 pm

    This should get you started if I understand right.

    string path = "C:\\TestLoadFiles.xml";
    string xmldoc = File.ReadAllText(path);
    
    using (XmlReader reader = XmlRead.Create(xmldoc))
    {
        reader.MoveToContent();
        label_sourceId.Text = reader.GetAttribute("sourceId");
        label_description.Text = reader.GetAttribute("description");
        // ... for each label if everything will always be the same
        // might be better to read in the file, verify it, then set your labels
    }
    

    EDIT:
    Actually a switch might be better:

    while (reader.MoveToNextAttribute())
    {
      switch (reader.Name)
      {
        case "description":
          if (!string.IsNullOrEmpty(reader.Value))
            label_description.Text = reader.Value;
          break;
        case "sourceId":
          if (!string.IsNullOrEmpty(reader.Value))
            label_sourceId.Text = reader.Value;
          break;
        // ...
      }
    }  
    

    EDIT2:

    So the listbox contains the file name.

    private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
        string path = (string)listBox1.SelectedItem;
        DisplayFile(path);
    } 
    private void DisplayFile(string path)
    {
        string xmldoc = File.ReadAllText(path);
    
        using (XmlReader reader = XmlRead.Create(xmldoc))
        {   
    
            while (reader.MoveToNextAttribute())
            {
              switch (reader.Name)
              {
                case "description":
                  if (!string.IsNullOrEmpty(reader.Value))
                    label_description.Text = reader.Value; // your label name
                  break;
                case "sourceId":
                  if (!string.IsNullOrEmpty(reader.Value))
                    label_sourceId.Text = reader.Value; // your label name
                  break;
                // ... continue for each label
               }
            }
        }
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a listbox in which i have to give minimum 2 files for
I have a listbox that has a datatemplate which contains multiple text boxes. I
I have a form that has two buttons, textbox, listbox, and a combobox. The
I have two listbox in windows Form c#, the first one has all valid
I have a ListBox with ItemsPanelTemplate of WrapPanel. There's some left & right padding
I have ListBox called lstProductGroups. On a simple Windows Form, a method called GetGroups
I have an ASP.NET webform that has a listbox ( lbxRegions ) with multi-select
I have two classes A & B, and a listbox. I assign listBox.ItemsSource equal
I have a ListBox that has a grid in its template to allow 4
I have an iFrame which has it's source set to another aspx page. The

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.