Search This Blog

Tuesday, January 3, 2012

Better folder browser dialog in WinForms

The FolderBrowserDialog provided by .NET is just plain bad, the one that comes standard with Vista/7 is so much better..
So, download Windows API Code Pack, and then

using Microsoft.WindowsAPICodePack.Dialogs; 
and

using (Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog folderDialog = new Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog())
{
folderDialog.IsFolderPicker = true;
if (folderDialog.ShowDialog() == CommonFileDialogResult.Ok)
{
string folder = folderDialog.FileName;
}
}
This will give you a dialog like this:

3 comments:

  1. You failed to mention one thing. You have to add two references in your solution explorer.

    1. Microsoft.WindowsAPICodePack
    2. Microsoft.WindowsAPICodePack.Shell

    ReplyDelete
  2. Thanks for this.

    ReplyDelete