Codingale
Codingale

Reputation: 218

How do a make this type of select folder dialog in C#?

So I recently tried to the FolderBrowserDialog but much to my disappointment it was not like the following screenshot:

http://i.imgur.com/s2LHqxA.png

But instead it was formatted and as I think, hard to navigate with like this: http://i.imgur.com/rfSnt8C.png

How would I go about getting the other version where it's a dialog box asking for what folder to save to like the select file type natively, instead of what I think is this hard to navigate menu.

Upvotes: 4

Views: 8570

Answers (2)

Tal Halamish
Tal Halamish

Reputation: 106

The CommonOpenFileDialog class from the NuGet Package "Microsoft.WindowsAPICodePack-Shell" will answer your request.

Set IsFolderPicker property to true and that's it.

using Microsoft.WindowsAPICodePack.Dialogs;     

private bool SelectFolder(out string fileName)
{
    CommonOpenFileDialog dialog = new CommonOpenFileDialog();
    dialog.IsFolderPicker = true;
    if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
    {
        fileName = dialog.FileName;
        return true;
    }
    else
    {
        fileName = "";
        return false;
    }
}

Upvotes: 9

nayef harb
nayef harb

Reputation: 753

thats because you are using FolderBrowserDialog instead of OpenFileDialog

you can check the below

 private void btnBrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();
            fileDialog.Title = "Browse File";
            fileDialog.Filter = "All files (*.*)|*.*|All files (*.*)|*.*";
            fileDialog.FilterIndex = 2;
            fileDialog.InitialDirectory = "c:\\";
            fileDialog.RestoreDirectory = true;

            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                txtFileName.Text = fileDialog.FileName;
            }
        }

Upvotes: 1

Related Questions