How to get from folder only image files

BitSmithy 1,236 Reputation points
2020-01-13T21:48:36.167+00:00

I have code:
IReadOnlyList filesInOpenedFolder = await openedFolder.GetFilesAsync();

I want only get image files. Is it possible?
Acceptable is to get files with .gif, .jpg, .bmp extensions.

Universal Windows Platform (UWP)
{count} votes

Accepted answer
  1. Fay Wang - MSFT 5,121 Reputation points
    2020-01-14T01:43:35.023+00:00

    Hello,

    ​Welcome to Microsoft Q&A!

    You can use QueryOptions class to query the specified file type in app data folder.

    StorageFolder folder = ApplicationData.Current.LocalFolder;  
    List fileTypeFilter = new List();  
    fileTypeFilter.Add(".jpg");  
    fileTypeFilter.Add(".bmp");  
    fileTypeFilter.Add(".gif");  
    QueryOptions queryOptions = new QueryOptions(Windows.Storage.Search.CommonFileQuery.OrderByName, fileTypeFilter);  
    StorageFileQueryResult queryResult = folder.CreateFileQueryWithOptions(queryOptions);  
    var files = await queryResult.GetFilesAsync();  
    
    No comments

0 additional answers

Sort by: Most helpful