C#: Folder select dialog in style of OpenFileDialog

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

C#: Folder select dialog in style of OpenFileDialog

Postby MarauderIIC on Mon May 18, 2009 1:06 am

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.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 4:05 pm
Location: Maryland, USA

Return to Programming Discussion

Who is online

Users browsing this forum: No registered users and 1 guest