1

I have a WPF application where the user must choose a folder for an operation. I achieve this by opening a folder browser dialog when he clicks a button.

I want the dialog to both list external devices, like connected smartphones, and have a textbox where the user can enter a path to a folder and the dialog will be able to navigate to it, like the regular Windows dialogs work.

Currently I have:

    FolderItem ShellBrowseForFolder()
    {
        Folder folder = shell.BrowseForFolder(Hwnd, "", 0, 0);
        if (folder != null)
        {
            FolderItem fi = (folder as Folder3).Self;
            return fi;
        }

        return null;
    }

which I invoke by:

TargetFolderPath = ShellBrowseForFolder()?.Path;

This produces a folder browser dialog that looks like this:

Shell folder browser dialog

This dialog lists external devices but the user can't just type in "C:\some dir" and have the dialog navigate to it.

I've also tried providing options for the IShellDispatch.BrowseForFolder method (in accordance with these listed variants, after reading the MSDN article) like so:

Folder folder = shell.BrowseForFolder(Hwnd, "", 4, 0);

and

Folder folder = shell.BrowseForFolder(Hwnd, "", 0x00000004, 0);

but I haven't noticed anything changing.

The other dialog I have is:

readonly System.Windows.Forms.FolderBrowserDialog folderBrowser = new();

if (folderBrowser.ShowDialog() == DialogResult.OK)
    folderPath = folderBrowser.SelectedPath;

This produces dis:

System.Windows.Forms folder browser dialog

where the user CAN enter a path to a folder BUT this dialog does not show external devices, like connected smartphones.

Is there a way to get the best of both worlds?

Tessaract
  • 1,047
  • 7
  • 24

1 Answers1

0

You could try Ookii.Dialogs. Ookii.Dialogs.VistaFolderBrowserDialog should do what you want.

newky2k
  • 419
  • 5
  • 12
  • Thanks for the tip, even if it isn't an answer to the question, but I'd like my 3rd parties to have been made in this century. – Tessaract Jul 20 '21 at 22:00
  • No worries, though to be fair this was updated 8months ago and supports netcore and .net 5 -> https://www.nuget.org/packages/Ookii.Dialogs.Wpf. Also seems to do everything you need it too. :-) – newky2k Jul 21 '21 at 14:11
  • 1
    Oh, thanks! I saw the last post on that site was from 2017 and it required .Net Framework 3.5+ so I assumed the guy would at least update his own website. – Tessaract Jul 21 '21 at 15:34