blah blah blah is here! blah blah » Close

up1down
link

Is there a folder browser dialog box built in to WPF? If so, can someone point me in the right direction. If not (and I am guessing this is the case given my searching) can I reference System.Windows.Forms and use the dialog box from there? Would that have negative consequences?

last answered one year ago

1 answers

link

There isn't a WPF-specific FolderBrowserDialog but the Windows Forms version should work fine. Just add a reference to System.Windows.Forms.dll and then create it in the usual way.

As a general rule, it's best not to put 'using System.Windows.Forms;' at the top of the file as this can lead to ambiguity errors when WPF has similarly named controls etc.

So, just fully qualify everything:

var fbd = new System.Windows.Forms.FolderBrowserDialog();
fbd.RootFolder = Environment.SpecialFolder.Personal; // or whatever
string folder = null;
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
folder = fbd.SelectedPath;
}

eeboy
499

As usual... exactly what I needed. Slightly off topic but is there a way to get a combination of: Environment.SpecialFolder.MyComputer and Environment.SpecialFolder.Desktop. MyComputer provides exactly the view I need except that I'd like Desktop at the top.

vulpes
17279

You might be able to create a combined folder by juggling with the registry keys (see for example http://www.pctools.com/guides/registry/detail/73/) but this sort of stuff makes me nervous ;)

Feedback