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,673
  • 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
  • 60,314
  • 19
  • 104
  • 137
7

Check the FolderBrowserDialog class.

// ...    
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) 
{
    textBox1.Text = folderBrowserDialog1.SelectedPath;
}
Christian C. Salvadó
  • 769,263
  • 179
  • 909
  • 832
2

FolderBrowserDialog works just fine for this purpose.

itsmatt
  • 30,859
  • 10
  • 99
  • 162
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
  • 124,587
  • 78
  • 320
  • 501
0

Whatever you do, don't use the FolderBrowserDialog.

Just kidding. Use that.

recursive
  • 80,919
  • 32
  • 145
  • 234