-api-id | -api-type |
---|---|
T:Windows.Storage.Search.StorageFileQueryResult |
winrt class |
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.
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:
- StorageFolder.CreateFileQuery methods
- StorageFolder.CreateFileQueryWithOptions method
- FolderInformation.CreateFileQuery methods
- FolderInformation.CreateFileQueryWithOptions
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.
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