Created
November 14, 2017 21:51
-
-
Save jakesays-old/c97570401b227c36a77fc0a438442509 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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