BLOG.CSHARPHELPER.COM: Let the user select a folder in C#
Let the user select a folder in C#
This example demonstrates two handy techniques. First, when you click this program's ellipsis button, the following code displays a FolderBrowserDialog. This lets the user pick a directory instead of needing to type it in.
The code initializes the dialog to the directory path in the text box. (If this is not a valid path, the dialog defaults to its directory hierarchy root, in this case the Desktop. You can change the root by setting the dialog's RootFolder property at design time.)
The second useful technique is that the program saves the user's selection between runs. At design time I created a setting named Directory. When it starts, the program uses the following code to load the value saved in this setting.
Comments