Skip to content

Instantly share code, notes, and snippets.

@jakesays-old
Created November 14, 2017 21:51
Show Gist options
  • Save jakesays-old/c97570401b227c36a77fc0a438442509 to your computer and use it in GitHub Desktop.
Save jakesays-old/c97570401b227c36a77fc0a438442509 to your computer and use it in GitHub Desktop.
public static List<string> SelectFolders(IHostWindow hostWindow, SelectFolderOptions options)
{
Arguments.RequireNotNull(hostWindow, nameof(hostWindow));
Arguments.RequireNotNull(options, nameof(options));
Arguments.RequireNotNullOrEmpty(options.Title, nameof(options.Title));
var dlg = new CommonOpenFileDialog
{
EnsureReadOnly = options.EnsureReadOnly,
IsFolderPicker = true,
AllowNonFileSystemItems = false,
Title = options.Title,
AddToMostRecentlyUsedList = options.AddToMostRecentlyUsedList,
EnsurePathExists = options.EnsurePathExists,
Multiselect = true
};
if (options.InitialFolder.NotNullOrEmpty())
{
dlg.InitialDirectory = options.InitialFolder;
}
if (dlg.ShowDialog(hostWindow.Handle) != CommonFileDialogResult.Ok)
{
return null;
}
try
{
var selectedFiles = dlg.FilesAsShellObject.Select(s => s.ParsingName).ToList();
return selectedFiles;
}
catch
{
hostWindow.ShowErrorMessage("Could not create a ShellObject from the selected item");
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment