• 0

[C#] Anyone have sample code?


Question

I want to scan a local folder, find all .txt files in that folder, fill a collection/datasource with it, and then fill a ListBox. Anyone have some quick sample code?

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0
I want to scan a local folder, find all .txt files in that folder, fill a collection/datasource with it, and then fill a ListBox. Anyone have some quick sample code?

584799419[/snapback]

	 string[] files = Directory.GetFiles(Environment.CurrentDirectory, "*.txt");
 	 ArrayList _files = new ArrayList(files);
 	 listBox1.Items.AddRange(files);

Link to comment
Share on other sites

  • 0
?	string[] files = Directory.GetFiles(Environment.CurrentDirectory, "*.txt");
 ?	ArrayList _files = new ArrayList(files);
 ?	listBox1.Items.AddRange(files);

584799983[/snapback]

Thanks, that's perfect. It actually worked better like this:

string[] fileList = Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*.txt");
lstFiles.Items.AddRange(fileList);

Link to comment
Share on other sites

  • 0
Thanks, that's perfect. It actually worked better like this:

string[] fileList = Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*.txt");
lstFiles.Items.AddRange(fileList);

584800347[/snapback]

Um... yeah, I know. I put the ArrayList in there because you said you wanted to store the files in a collection. I know it was redundant, and I know an array is a collection, but I wasn't sure exactly what you're doing, so I erred on the side of too much info. :)

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.