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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:22:49+00:00 2026-05-21T16:22:49+00:00

I have a small problem here. I want to list my files from a

  • 0

I have a small problem here. I want to list my files from a directory in a listbox. and when I double click the files I want to display the file in a textbox.

I got this code, but my directory when double click are wrong.

Say i double click on battalionAPC.fbi
The directory diplay in textbox is C:\Users\Yvonne\Documents\Visual Studio 2010\Projects\ListBoxTest\ListBoxTest\bin[Debug\battalionAPC.fbi]

But the correct directory should be this:
C:\Users\Yvonne\Documents\Visual Studio 2010\Projects\ListBoxTest\ListBoxTest\bin[units\battalion\APC\battalionAPC.fbi]

**Differences mark using the [] brackets

Any idea how I could get the directory correct?

My full code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{


    public Form1()
    {
        InitializeComponent();
    }

    private void populateList(string path)
    {
        string[] dir = Directory.GetDirectories(path);
        foreach (string d in dir)
        {

            string entry = Path.GetFileName(d);
            //listBox1.Items.Add(entry);
            populateList(d);
        }
        string[] files = Directory.GetFiles(path);

        foreach (string f in files)
        {
            string entry1 = Path.GetFullPath(f);

            string entry = Path.GetFileName(f);
            if (entry.Contains(".fbi"))
            {
             listBox1.Items.Add(entry);
            }
        }
    }

    private void Form1_Load_1(object sender, EventArgs e)
    {
        populateList(@"..\units\battalion");
    }


    private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string file = listBox1.SelectedItem.ToString();
        textBox1.Text = file;

        string all = Path.GetFullPath(file);
        textBox2.Text = all;
    }

}
}
  • 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-21T16:22:50+00:00Added an answer on May 21, 2026 at 4:22 pm
    private void populateList( string path )
    {
        string[] files = Directory.GetFiles(path, "*.fbi", SearchOption.AllDirectories);
        foreach (string f in files)
        {
            string entry1 = Path.GetFullPath(f);
            string entry = Path.GetFileName(f);
            listBox1.Items.Add(entry);
        }
    }
    

    You can use Directory.GetFiles() to do more work for you by using the variation with three parameters. The second parameter already limits the files found to those with the .fbi extension, and SearchOption.AllDirectories handles going down into subdirectories so you don’t have to make populateList() recursive anymore.

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

Sidebar

Related Questions

I have a small problem, I want to load data from a PHP file
Here's the problem -- I have a few thousand small text snippets, anywhere from
I have a small problem with interfaces. Here it is in Pseudo code :
So here is our problem: We have a small team of developers with their
I have small problem with my .net 2.0 winforms application. I want to embed
I have a small problem with a script. I want to have a default
I have a small problem with how should i think a... problem. I want
I have a small problem with Smarty... I have two different template files in
I have a small problem where I want to find the next active item
I am a Python newbie. I have this small problem. I want to print

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.