I want to have a Folder browser in my application, but I don't want to use the FolderBrowserDialog. (For several reasons, such as it's painful to use)
I want to use the standard OpenFileDialog, but modified for the directories.
As an example, µTorrent has a nice implementation of it (Preferences/Directories/Put new downloads in:). The standard Open File Dialog enable the user to:
Does anybody know how to implement this? In C#.
WindowsAPICodePack
var dlg = new Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog();
dlg.IsFolderPicker = true;
I am not sure about uTorrent but this sounds pretty much like new Vista's IFileDialog with FOS_PICKFOLDERS option set. Generic C# code for it would go something like:
var frm = (IFileDialog)(new FileOpenDialogRCW());
uint options;
frm.GetOptions(out options);
options |= FOS_PICKFOLDERS;
frm.SetOptions(options);
if (frm.Show(owner.Handle) == S_OK) {
IShellItem shellItem;
frm.GetResult(out shellItem);
IntPtr pszString;
shellItem.GetDisplayName(SIGDN_FILESYSPATH, out pszString);
this.Folder = Marshal.PtrToStringAuto(pszString);
}
Full code can be found here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With