0

Good day all, I have read through all the posts I could find, but none helped me. I have a listbox that should list all the files in a folder called data that is in the same location as my app. Problem is, I tried varies codes but i'm still failing to get the folder to show in my listbox. The filepath is variable as the exe file is in diff locations on diff pc's. Here is my code:

string Cust = System.AppDomain.CurrentDomain.BaseDirectory + @"data\";
string[] txtfiles = Directory.GetFiles(Cust, "*.txt");
foreach (string file in txtfiles)
    custList.Items.Add(file);

When I finally get the files to list, I will need to be able to click on one and have its values display in labels on my form.

Any help would be great. Thanx

Simeon EM
  • 1
  • 6

1 Answers1

0

Your code should work, your problem is most likely how you are concatenating your path:

Change:

string Cust = System.AppDomain.CurrentDomain.BaseDirectory + @"data\";

To:

string Cust = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "data");
Kevin
  • 2,566
  • 1
  • 11
  • 12
  • Thanx, but still, no info in my listbox. I have added system.io, It has to be the path? – Simeon EM Dec 02 '18 at 16:51
  • Gave this a try now: < private void MarkitUp_Load(object sender, EventArgs e) { PopulateListBox(custList, System.AppDomain.CurrentDomain.BaseDirectory + "data", "*.txt"); > , but still not displaying. – Simeon EM Dec 02 '18 at 16:58
  • Found the guilty party. When I created the files, I never specified the filetype. Added the filetype .txt to where the file is created, now its working. thanx – Simeon EM Dec 02 '18 at 17:18