I want the user to select a directory where a file that I will then generate will be saved. I know that in WPF I should use the OpenFileDialog
from Win32, but unfortunately the dialog requires file(s) to be selected – it stays open if I simply click OK without choosing one. I could "hack up" the functionality by letting the user pick a file and then strip the path to figure out which directory it belongs to but that's unintuitive at best. Has anyone seen this done before?
Wpf – Open directory dialog
dialogfilesystemswpf
Related Topic
- Android – How to prevent a dialog from closing when a button is clicked
- C# – WPF copy file to the predefined directory
- C# – How to show a Save As dialog in WPF
- Javascript – How to create a dialog with “yes” and “no” options
- Node.js – Remove directory which is not empty
- How to create a directory using Ansible
Best Answer
You can use the built-in FolderBrowserDialog class for this. Don't mind that it's in the
System.Windows.Forms
namespace.If you want the window to be modal over some WPF window, see the question How to use a FolderBrowserDialog from a WPF application.
EDIT: If you want something a bit more fancy than the plain, ugly Windows Forms FolderBrowserDialog, there are some alternatives that allow you to use the Vista dialog instead:
Third-party libraries, such as Ookii dialogs (.NET 4.5+)
The Windows API Code Pack-Shell:
Note that this dialog is not available on operating systems older than Windows Vista, so be sure to check
CommonFileDialog.IsPlatformSupported
first.