Sdílet prostřednictvím


StorageFileQueryResult Class

Definition

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.

public ref class StorageFileQueryResult sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
class StorageFileQueryResult final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
public sealed class StorageFileQueryResult
Public NotInheritable Class StorageFileQueryResult
Inheritance
Object Platform::Object IInspectable StorageFileQueryResult
Attributes
Implements

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

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.

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:

Properties

Folder

Gets the folder that was queried to create the StorageFileQueryResult object. This folder represents the scope of the query.

Methods

ApplyNewQueryOptions(QueryOptions)

Modifies query results based on new QueryOptions.

FindStartIndexAsync(Object)

Retrieves the index of the file from the query results that most closely matches the specified property value (or file, if used with FileActivatedEventArgs.NeighboringFilesQuery). The property that is matched is determined by the first SortEntry of the QueryOptions.SortOrder list.

GetCurrentQueryOptions()

Retrieves the query options used to determine query results.

GetFilesAsync()

Retrieves a list of all the files in the query result set.

GetFilesAsync(UInt32, UInt32)

Retrieves a list of files in a specified range.

GetItemCountAsync()

Retrieves the number of files in the set of query results.

GetMatchingPropertiesWithRanges(StorageFile)

Gets matching file properties with corresponding text ranges.

Events

ContentsChanged

Fires when a file is added to, deleted from, or modified in the folder being queried. This event only fires after GetFilesAsync has been called at least once.

OptionsChanged

Fires when the query options change.

Applies to

See also