Skip to content

Latest commit

 

History

History
59 lines (43 loc) · 3.37 KB

storagefilequeryresult.md

File metadata and controls

59 lines (43 loc) · 3.37 KB
-api-id -api-type
T:Windows.Storage.Search.StorageFileQueryResult
winrt class

Windows.Storage.Search.StorageFileQueryResult

-description

Provides access to the results of a query of the files in the location that is represented by a StorageFolder object. You can use StorageFileQueryResult to enumerate the files in that StorageFolder location.

-remarks

Note

Although it's not attributed with marshalling_behavior(agile), this class can be treated as agile.

You can get a StorageFileQueryResult object by calling the following methods from a StorageFolder or a FolderInformation object:

-examples

This example demonstrates how to get a list of files from a StorageFileQueryResult object.

// Set query options with filter and sort order for results
List<string> fileTypeFilter = new List<string>();
fileTypeFilter.Add(".jpg");
fileTypeFilter.Add(".png");
fileTypeFilter.Add(".bmp");
fileTypeFilter.Add(".gif");
var queryOptions = new QueryOptions(CommonFileQuery.OrderByName, fileTypeFilter);

// Create query and retrieve files
var query = KnownFolders.PicturesLibrary.CreateFileQueryWithOptions(queryOptions);
IReadOnlyList<StorageFile> fileList = await query.GetFilesAsync();
// Process results
foreach (StorageFile file in fileList)
{
    // Process file
}

The query variable gets the StorageFileQueryResult that is used to retrieve files that meet the criteria of the query.

Note

You need the Pictures library capability to access the library using KnownFolders.PicturesLibrary. To learn more about capabilities and file access, see File access permissions.

-see-also

Windows.Storage.storageFolder.createFileQuery methods, Windows.Storage.storageFolder.createFileQueryWithOptions method, Windows.Storage.BulkAccess.folderInformation.createFileQuery, Windows.Storage.BulkAccess.folderInformation.createFileQueryWithOptions, File search sample (Windows 10), Folder enumeration sample