3

What's the best way to let a user pick a subdirectory in C#?

For example, an app that lets the user organize all his saved html receipts. He most likely is going to want to be able to select a root subdirectory that the program should search for saved webpages (receipts).

Duplicate:

Community
  • 1
  • 1
Fred
  • 2,713
  • 3
  • 27
  • 30

5 Answers5

11

The Folder Browser Dialog is the way to go.

If you want to set an initial folder path, you can add this to your form load event:

// Sets "My Documents" as the initial folder path
string myDocsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
FolderBrowserDialog1.SelectedPath = myDocsPath;
John Rasch
  • 62,489
  • 19
  • 106
  • 139
7

Check the FolderBrowserDialog class.

// ...    
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) 
{
    textBox1.Text = folderBrowserDialog1.SelectedPath;
}
Christian C. Salvadó
  • 807,428
  • 183
  • 922
  • 838
2

FolderBrowserDialog works just fine for this purpose.

itsmatt
  • 31,265
  • 10
  • 100
  • 164
2

FolderBrowserDialog works, but offers very little customization.

If you want a textbox where users can type in the path have a look here

Dupe of: Browse for a directory in C#

Community
  • 1
  • 1
Sam Saffron
  • 128,308
  • 78
  • 326
  • 506
0

Whatever you do, don't use the FolderBrowserDialog.

Just kidding. Use that.

recursive
  • 83,943
  • 34
  • 151
  • 241