title: C# Open files from listbox file listing
body: <p>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. </p>
  
  <p>I got this code, but my directory when double click are wrong. </p>
  
  <p>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] </p>
  
  <p>But the correct directory should be this: 
  C:\Users\Yvonne\Documents\Visual Studio 2010\Projects\ListBoxTest\ListBoxTest\bin[units\battalion\APC\battalionAPC.fbi]</p>
  
  <p>**Differences mark using the [] brackets</p>
  
  <p>Any idea how I could get the directory correct? </p>
  
  <p>My full code: </p>
  
  <pre><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;
      }
  
  }
  }
  </code></pre>