How to allow the user to browse for directories in Winforms App using C# ?

There are times when you want to allow the user to browse for files and select one in your Windows Application .

The Winforms provides the FolderBrowserDialog class which can be used to select a file interactively.

How to allow the user to browse for directories in Winforms App using C# ?

Below is a sample code snippet demonstrating how to allow the user to select a file.

FolderBrowserDialog ACfileDialog = new FolderBrowserDialog();
if (ACfileDialog.ShowDialog() == DialogResult.OK)
{
    MessageBox.Show(ACfileDialog.SelectedPath);
}