Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to set FolderBrowserDialog.RootFolder to an arbitrary path from a string?

Tags:

c#

.net

winforms

I'm trying to do this

FolderBrowserDialog dlg = new FolderBrowserDialog();
dlg.RootFolder = "C:\SomeUserSelectedFolder";

But RootFolder is a System.Environment.SpecialFolder.

Does this mean I can only set that to places like MyDocuments or the Desktop?!?

like image 399
Almo Avatar asked Oct 18 '11 14:10

Almo


1 Answers

That's correct: if the assigned value of RootFolder is not one of the Environment.SpecialFolder values then an InvalidEnumArgumentException is raised.

You can set SelectedPath, though:

If the SelectedPath property is set before showing the dialog box, the folder with this path will be the selected folder, as long as SelectedPath is set to an absolute path that is a subfolder of RootFolder (or more accurately, points to a subfolder of the shell namespace represented by RootFolder).

like image 160
stuartd Avatar answered Oct 15 '22 21:10

stuartd