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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:08:56+00:00 2026-05-30T09:08:56+00:00

I would like to populate my ListBox with whatever items there is in the

  • 0

I would like to populate my ListBox with whatever items there is in the specific path.

string path = @"C:\users\test\desktop";

So whatever items there are on my desktop, the listbox should have those items in it.

I tried making the ListBox1.ItemSource = path , but all that does is it writes the path to the listbox :(.

Any suggestions or help.

Thanks

  • 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-30T09:08:58+00:00Added an answer on May 30, 2026 at 9:08 am

    Take a look at this article. Specifically, these sections:

    Once you setup your project properties, open the XAML file and add a Button called “Read File” and attach a Click_Event to it. We will also add a ListBox, so that we can display the text content inside it. Here is the code snippet of the same:

    <UserControl x:Class="FileAccessDemo.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    
        <StackPanel x:Name="LayoutRoot" Background="White">
            <Button Width="150" Height="26" Content="Read File" Click="Button_Click"/>
            <ListBox x:Name="lstContent"/>
        </StackPanel>
    </UserControl>
    

    Now we need to implement the Click event logic for the Button. To do this, go to the code behind file and write your own logic to read any file present in your system. In our example, we will use the System.IO.File class and read the hosts file. Then we will add the content in our ListBox.

    Here is the code implementation:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        string fileContent = File.ReadAllText(@"c:\windows\system32\drivers\etc\hosts");
        lstContent.Items.Add(fileContent);
    }
    

    Just call the File.ReadAllText() method and pass the complete file path as the parameter. This will read the content and store it in a local variable called fileContent. Now add the content to our ListBox.

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

Sidebar

Related Questions

I would like to populate a DateTime structure from a string, but it is
I have a view that I would like to populate data when the next
I have two divs. I would like to move/populate the text from div id
I have a typed dataset in my project. I would like to populate a
I have a continuous form that i would like to populate via a sql
I have an (access) database table which contains data I would like to populate
I have a GUI created in Glade, and I would like to populate the
I have 5 static values I would like to populate in a ListPicker control,
I have a DDL and ASP.NET Textbox. I would like to populate the text
I would like to populate a Treeview. Here is what I have in DB

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.