This API will be removed in WASDK v1.8
or any future version that introduces the Picker API.
SavePicker, FilePicker and FolderPicker which support AOT, Packaged/UnPackaged and Elevated Apps.
you can use simple methods which return a string
or List<string>
or you can use Async
methods which return a StorageFile
or StorageFolder
If you want to set DefaultFileExtension
, you need to set your FileTypeChoices item Key
. for example: picker.DefaultFileExtension = "Images";
FilePicker
Property
Name |
Options |
ShowDetailedExtension |
CommitButtonText |
SuggestedFileName |
DefaultFileExtension |
InitialDirectory |
SuggestedStartLocation |
Title |
FileTypeChoices |
ShowAllFilesOption |
PickSingleFile/PickSingleFileAsync
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| var picker = new FilePicker(Hwnd); picker.Title = "Custom Title"; picker.SuggestedFileName = "Default FileName"; picker.DefaultFileExtension = "*.*"; picker.ShowAllFilesOption = true; picker.CommitButtonText = "Custom Confirm"; picker.FileTypeChoices = new Dictionary<string, IList<string>> { { "Images", new List<string> { "*.png", "*.jpg", "*.jpeg", "*.bmp", "*.gif" } }, { "Text Files", new List<string> { "*.txt", "*.md", "*.log" } } };
picker.InitialDirectory = @"C:\";
var file = await picker.PickSingleFileAsync(); if (file != null) { Txt.Text = file.Path; }
|
PickMultipleFiles/PickMultipleFilesAsync
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| var picker = new FilePicker(Hwnd); picker.Title = "Custom Title"; picker.SuggestedFileName = "Default FileName"; picker.DefaultFileExtension = "*.*"; picker.ShowAllFilesOption = true; picker.CommitButtonText = "Custom Confirm"; picker.FileTypeChoices = new Dictionary<string, IList<string>> { { "Images", new IList<string> { "*.png", "*.jpg", "*.jpeg", "*.bmp", "*.gif" } }, { "Text Files", new IList<string> { "*.txt", "*.md", "*.log" } } };
picker.InitialDirectory = @"C:\";
var files = await picker.PickMultipleFilesAsync(); StringBuilder stringBuilder = new StringBuilder(); foreach (var item in files) { stringBuilder.AppendLine(item.Path); } Txt.Text = stringBuilder.ToString();
|
SavePicker
Property
Name |
Options |
ShowDetailedExtension |
CommitButtonText |
SuggestedFileName |
DefaultFileExtension |
InitialDirectory |
SuggestedStartLocation |
Title |
FileTypeChoices |
ShowAllFilesOption |
PickSaveFile/PickSaveFileAsync
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| var picker = new SavePicker(Hwnd); picker.Title = "Custom Title"; picker.SuggestedFileName = "Default FileName"; picker.DefaultFileExtension = "*.*"; picker.ShowAllFilesOption = true; picker.CommitButtonText = "Custom Confirm"; picker.FileTypeChoices = new Dictionary<string, IList<string>> { { "Images", new IList<string> { "*.png", "*.jpg", "*.jpeg", "*.bmp", "*.gif" } }, { "Text Files", new IList<string> { "*.txt", "*.md", "*.log" } } };
picker.InitialDirectory = @"C:\";
var file = await picker.PickSaveFileAsync(); if (file != null) { Txt.Text = file.Path; }
|
FolderPicker
Property
Name |
Options |
CommitButtonText |
SuggestedFileName |
InitialDirectory |
SuggestedStartLocation |
Title |
PickSingleFolder/PickSingleFolderAsync
1 2 3 4 5 6 7 8 9 10 11 12 13
| var picker = new FolderPicker(Hwnd); picker.Title = "Custom Title"; picker.CommitButtonText = "Custom Confirm"; picker.InitialDirectory = @"C:\";
var file = await picker.PickSingleFolderAsync(); if (file != null) { Txt.Text = file.Path; }
|
PickMultipleFolders/PickMultipleFoldersAsync
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| var picker = new FolderPicker(Hwnd); picker.Title = "Custom Title"; picker.CommitButtonText = "Custom Confirm"; picker.InitialDirectory = @"C:\";
var files = await picker.PickMultipleFoldersAsync(); StringBuilder stringBuilder = new StringBuilder(); foreach (var item in files) { stringBuilder.AppendLine(item.Path); } Txt.Text = stringBuilder.ToString();
|
Demo
you can run demo and see this feature.
