Search code examples
c#openfiledialog

Use Openfiledialog to browser folder


Can I Use Openfiledialog to browser folder? Because I really hate using FolderBrowserDialog().


Solution

  • I had the same issue in one of my projects and found a solution. You can use it if you get the Microsoft.WindowsAPICodePack-Shell nuget package and use the Microsoft.WindowsAPICodePack.Dialogs namespace. Use it as such:

    CommonOpenFileDialog dialog = new CommonOpenFileDialog
        {
                IsFolderPicker = true
        };
    if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
        {
                // the selected directory is in dialog.FileName
        }