Show only folders with WinRT Folder picker

362 views Asked by At

When using the WinRT folder picker it seems we are forced to either allow files of at least one type to be shown as well, or else must use a fake file extension to filter out all files which in turn means thumbnails cannot be used for folders.

   try
    {
       var picker = new FolderPicker { ViewMode = PickerViewMode.List };
       picker.FileTypeFilter.Add(".fake");

       var folder = await picker.PickSingleFolderAsync();
       if (folder == null) return;

       StorageApplicationPermissions.FutureAccessList.AddOrReplace("taggingFolder", folder);
       this.Frame.Navigate(typeof(MediaItemPicker), folder.Path);
    }
    catch (TaskCanceledException ex) {
       System.Diagnostics.Debug.WriteLine(ex.Message);
    }

Is this as good as it gets or am I missing something? Note that not adding an extension throws a runtime exception.

1

There are 1 answers

1
Rob Caplan - MSFT On BEST ANSWER

The folder picker will pick only folders, but it will show files of the filtered type so users can know what is already in the folders they pick. Typically apps add file types that the app will handle within the picked folder.

If you filter on a fake type then it is unlikely the user will have any files of that type to show.

The filter isn't related to the thumbnail. Your code with the .fake filter shows thumbnails if you set the ViewMode to PickerViewMode.Thumbnail instead of List.