I'm trying to walk through a whole directory tree and print out all the file names on a listbox control. I wrote some code but there are errors. Not sure what I'm doing wrong. By the way, this is in C# using WPF in Visual Studio.
Here is the whole project solution in Visual Studio: http://tinyurl.com/a2r5jv9
Here is the code from MainWindow.xaml.cs if you don't want to download the project solution: http://pastebin.com/cWRTeq3N
I'll paste the code here as well.
public partial class MainWindow : Window { private void Button_Click_1(object sender, RoutedEventArgs e) { string sourcePath = @"C:\temp\"; static void DirSearch(string sourcePath) { try { foreach (string d in Directory.GetDirectories(sourcePath)) { foreach (string f in Directory.GetFiles(d)) { listBox1.Items.Add(f); } DirSearch(d); } } catch (Exception ex) { listBox1.Items.Add(ex.Message); } } } }