JinX JinX - 1 year ago 218
C# Question

How to use OpenFileDialog to select a folder?

How to use

to select folders?

I was going to use the following project: https://github.com/scottwis/OpenFileOrFolderDialog

However, I faced one problem. It uses the
function and
structure. And
has the member named
. It's the identifier for dialog template. And the project contains the
file and the templated dialog init, too. But I couldn't figure out how to attach this file to my C# project.

Is there a better way to use an
to select folders?

Answer Source

Basically you need the FolderBrowserDialog class:

Prompts the user to select a folder. This class cannot be inherited.


FolderBrowserDialog fbd = new FolderBrowserDialog();

DialogResult result = fbd.ShowDialog();

if (!string.IsNullOrWhiteSpace(fbd.SelectedPath))
    string[] files = Directory.GetFiles(fbd.SelectedPath);

    System.Windows.Forms.MessageBox.Show("Files found: " + files.Length.ToString(), "Message");


If you work in WPF you have to add the reference to System.Windows.Forms.

you also have to add using System.IO for Directory class

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download