Reputation: 218
So I recently tried to the FolderBrowserDialog
but much to my disappointment it was not like the following screenshot:
But instead it was formatted and as I think, hard to navigate with like this:
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
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
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