Page 1 of 1

C#: Folder select dialog in style of OpenFileDialog

Posted: Mon May 18, 2009 12:06 am
by MarauderIIC
If you spend forever looking for this, as I did, here's some information.
1) This blog entry contains source for such a dialog, however, it contains C resource files, and as such is not compatible when running a C# application in Mono.

2) This StackOverflow post contains a bunch of information.

In short, it's pretty much impossible to make a portable solution that is easy to use (unlike the FolderBrowserDialog, which is ugly and hard to use). What I did was I made a textbox with a browse button next to it. When browse is pressed, a FolderBrowserDialog is shown with its SelectedPath set to the textbox's value. This makes the FolderBrowserDialog open at the specified location. So, better than nothing, and if you have a general idea, you can at least start close :/
if (string.IsNullOrEmpty(textbox.Text)) then the SelectedPath is Application.StartupPath, which makes it start where the .exe is. Better than desktop or whatever the heck the stupid default is, at least.