我尝试从文件夹中仅选择所需文件,如下所示:
var folderPicker = new Windows.Storage.Pickers.FolderPicker
{
ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail,
SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop
};
folderPicker.FileTypeFilter.Add(".mp3");
folderPicker.FileTypeFilter.Add(".mp4");
folderPicker.FileTypeFilter.Add(".jpeg");
folderPicker.FileTypeFilter.Add(".jpg");
folderPicker.FileTypeFilter.Add(".png");
除了".mp3"
,".mp4"
,".jpeg"
,".jpg"
和".png"
之类的文件之外,不应选择所有其他文件类型。但是不幸的是,代码还添加了所有尚未添加到FileTypeFilter的所有其他文件。
代码中缺少什么?
答案 0 :(得分:1)
尝试下面的代码(Microsoft https://docs.microsoft.com/en-us/windows/uwp/files/quickstart-using-file-and-folder-pickers)
var picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
picker.SuggestedStartLocation =
Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
picker.FileTypeFilter.Add(".jpg");
picker.FileTypeFilter.Add(".jpeg");
picker.FileTypeFilter.Add(".png");
Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();