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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:19:57+00:00 2026-06-07T15:19:57+00:00

I enumerated directories into a ListBox using this: private void TE_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)

  • 0

I enumerated directories into a ListBox using this:

private void TE_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {            
IEnumerable<string> file = System.IO.Directory.EnumerateDirectories(@"C:\Users\user\Desktop", "*.*", System.IO.SearchOption.AllDirectories);
        foreach (var f in file)
        {
            lbz.Items.Add(String.Format(f));
        }
    } 

Now, the ListBox displays all the directories in that given path, then I use:

private void lbz_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (lbz.SelectedItem != null)
        {
            if (Directory.Exists(lbz.SelectedItem.ToString()))
            {
                string[] filePaths = Directory.EnumerateFiles() //:<------
                for (int i = 0; i < filePaths.Length; ++i) 
                {
                    lbz2.Items.Add(i); 
                }

            }
            else
            {
                tb1.Text = "Directory Doesn't Exist On This Path";
            }
        }
        else
        {
            tb1.Text = "No Directory Selected";
        }

    }

The arrow is where I’m stumped, since I’m using Microsoft Visual Web Developer I can’t use GetFiles, I have to use Enumerate.

I want to be able to populate another ListBox (lbz2) by selecting a directory in lbz and having that directories contents, all the files in it, displayed in lbz2.

If:

string[] filePaths = Directory.EnumerateFiles() //:<------
for (int i = 0; i < filePaths.Length; ++i) 
{
    lbz2.Items.Add(i); 
}

doesn’t work, I’m open to suggestions.

  • 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-07T15:19:59+00:00Added an answer on June 7, 2026 at 3:19 pm

    This should work:

    foreach (var filePath in Directory.EnumerateFiles(lbz.SelectedItem.ToString()))
    {
        lbz2.Items.Add(filePath); 
    }
    

    EnumerateFiles returns IEnumerable<string>, not string[].

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

Sidebar

Related Questions

I have this code @Column(updatable=false) @Enumerated(EnumType.STRING) private ExamType examType; However, I can still change
It's possible to define enumerations in JPA using either @Enumerated(EnumType.ORDINAL) or @Enumerated(EnumType.STRING) I wonder
I enumerated the RAS capable devices using RasEnumDevices and I am getting the DeviceName
For my trading program, a Merchant object has a qualities HashMap of enumerated Qualities
I have an enumerated type, StackID , and I am using the enumeration to
I was previously using How can a formcollection be enumerated in ASP.NET MVC? 's
Hibernates is generating a VARBINARY column with JPA @Enumerated annotation. I'm using SQL Server
Previously I've defined enumerated types that are intended to be private in the header
Arrays can be indexed using user-defined enumerated types. For example: type TIndexValue = (ZERO
I have an XSD file with an enumerated type. I'd like to create an

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.