Almo
Almo

Reputation: 15871

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

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?!?

Upvotes: 5

Views: 13480

Answers (1)

stuartd
stuartd

Reputation: 73313

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).

Upvotes: 12

Related Questions