Home

Awesome

BetterFolderBrowser

bfb-nuget wk-donate

BetterFolderBrowser is a .NET component library that was written to help developers provide a better folder-browsing and selection experience to users by employing a similar browser dialog as the standard OpenFileDialog in place of the current FolderBrowserDialog which only allows for single-folder selections with its tree-view display format. This allows for a much easier viewing, modification, searching and selection experience using the standard Windows Explorer dialog.

Here's a preview of the library in action:

bfb-preview-01 bfb-usage

Installation

To install via the NuGet Package Manager Console, type:

Install-Package BetterFolderBrowser

Features

Here are two examples of properties implementing the given custom editors:

    // Allows selection of one folder.
    [Editor(typeof(SelectedPathEditor), typeof(UITypeEditor))]
    public string MyFolderPath { get; set; }
    
    // Allows selection of many folders.
    [Editor(typeof(SelectedPathsEditor), typeof(UITypeEditor))]
    public string[] MyFolderPaths { get; set; }

Usage

If you prefer working with the Designer, simply add the component to Visual Studio's Toolbox and use the Properties window to change its options:

bfb-properties

To use it in code, first import WK.Libraries.BetterFolderBrowserNS - the code below will then assist you:

    var betterFolderBrowser = new BetterFolderBrowser();

    betterFolderBrowser.Title = "Select folders...";
    betterFolderBrowser.RootFolder = "C:\\";
    
    // Allow multi-selection of folders.
    betterFolderBrowser.Multiselect = true;

    if (betterFolderBrowser.ShowDialog() == DialogResult.OK)
    {
        string[] selectedFolders = betterFolderBrowser1.SelectedFolders;
        
        // If you've disabled multi-selection, use 'SelectedFolder'.
        // string selectedFolder = betterFolderBrowser1.SelectedFolder;
    }

If you'd prefer blocking the main UI thread when calling the dialog, simply specify the window owner of the dialog using the ShowDialog(IWin32Window) method:

    if (betterFolderBrowser.ShowDialog(this) == DialogResult.OK)
    {
        // ...
    }

Note that we've specified the owner with the keyword this since we're calling the dialog from the Form where it is hosted.

If you're calling the dialog from within a custom UserControl and would prefer blocking the main UI thread when calling it, you can still specify the window owner using the ShowDialog(IWin32Window) method:

    if (betterFolderBrowser.ShowDialog(this.FindForm()) == DialogResult.OK)
    {
        // ...
    }

Made with 💛 by Willy Kimura