StorageFileQueryResult StorageFileQueryResult StorageFileQueryResult StorageFileQueryResult 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.

Syntax

Declaration

public sealed class StorageFileQueryResultpublic sealed class StorageFileQueryResultPublic NotInheritable Class StorageFileQueryResult

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
}

// Set query options with filter and sort order for results
var fileTypeFilter = [".jpg", ".png", ".bmp", ".gif"];
var queryOptions = new Windows.Storage.Search.QueryOptions(search.CommonFileQuery.orderByName, fileTypeFilter);

// Create query and retrieve files
var query = Windows.Storage.KnownFolders.picturesLibrary.createFileQueryWithOptions(queryOptions);
query.getFilesAsync().done(function (files) {
    // Process results
    files.forEach(function (file) {
        // 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 PicturesLibrary. To learn more about capabilities and file access, see File access permissions.

Properties summary

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

Methods summary

Modifies query results based on new QueryOptions.

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

Retrieves the query options used to determine query results.

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

Retrieves a list of files in a specified range.

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

Gets matching file properties with corresponding text ranges.

Events summary

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

Fires when the query options change.

Properties

Methods

  • ApplyNewQueryOptions(Windows.Storage.Search.QueryOptions)
    ApplyNewQueryOptions(Windows.Storage.Search.QueryOptions)
    ApplyNewQueryOptions(Windows.Storage.Search.QueryOptions)
    ApplyNewQueryOptions(Windows.Storage.Search.QueryOptions)

    Modifies query results based on new QueryOptions.

    public void ApplyNewQueryOptions(Windows.Storage.Search.QueryOptions newQueryOptions)public void ApplyNewQueryOptions(Windows.Storage.Search.QueryOptions newQueryOptions)Public Function ApplyNewQueryOptions(newQueryOptions As Windows.Storage.Search.QueryOptions) As void

    Parameters

    Remarks

    This method causes the OptionsChanged event to fire.

    When this method returns, subsequent calls to GetFilesAsync(System.UInt32,System.UInt32) or GetItemCountAsync() will reflect the results of the new QueryOptions.

  • FindStartIndexAsync(System.Object)
    FindStartIndexAsync(System.Object)
    FindStartIndexAsync(System.Object)
    FindStartIndexAsync(System.Object)

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

    public IAsyncOperation<uint> FindStartIndexAsync(System.Object value)public IAsyncOperation<uint> FindStartIndexAsync(System.Object value)Public Function FindStartIndexAsync(value As System.Object) As IAsyncOperation( Of uint )

    Parameters

    • value
      System.Object
      System.Object
      System.Object
      System.Object

      The property value to match when searching the query results. The property to that is used to match this value is the property in the first SortEntry of the SortOrder list.

      Or, the file to match when searching with NeighboringFilesQuery.

    Returns

    • When this method completes successfully, it returns the index of the matched file in the query results or the index of the file in the NeighboringFilesQuery. In the latter case, the file is expected to be sourced from Files. If this function fails, it returns uint.MaxValue.

    Remarks

    You can use this method in conjunction with NeighboringFilesQuery to iterate between neighboring files while preserving the original view's sort order.

    Examples

    This example shows how to find the first song in an album that has a title beginning with the "R" in a set of query results that contains songs grouped by album title.

    
    QueryOptions queryOptions = new QueryOptions();
    queryOptions.FolderDepth = FolderDepth.Deep;
    queryOptions.IndexerOption = IndexerOption.OnlyUseIndexer;
    SortEntry album = new SortEntry();
    album.AscendingOrder = true;
    album.PropertyName = "System.Music.AlbumTitle";
    queryOptions.SortOrder.Add(album);
    
    StorageFileQueryResult queryResult = musicFolder.CreateFileQueryWithOptions(queryOptions);
    var firstIndex = await queryResult.FindStartIndexAsync("R");
    
    var queryOptions = new Windows.Storage.Search.QueryOptions();
    queryOptions.folderDepth = Windows.Storage.Search.FolderDepth.deep;
    queryOptions.indexerOption = Windows.Storage.Search.IndexerOptions.onlyUseIndexer;
    queryOptions.sortOrder.append({
     ascendingOrder: true,
     propertyName: "System.Music.AlbumTitle"
    });
    
    var queryResult = Windows.Storage.KnownFolders.picturesLibrary.createFileQueryWithOptions(queryOptions);
    var firstIndex = queryResult.findStartIndexAsync("R");
    
  • GetCurrentQueryOptions()
    GetCurrentQueryOptions()
    GetCurrentQueryOptions()
    GetCurrentQueryOptions()

    Retrieves the query options used to determine query results.

    public QueryOptions GetCurrentQueryOptions()public QueryOptions GetCurrentQueryOptions()Public Function GetCurrentQueryOptions() As QueryOptions

    Returns

  • GetFilesAsync()
    GetFilesAsync()
    GetFilesAsync()
    GetFilesAsync()

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

    public IAsyncOperation<StorageFile>> GetFilesAsync()public IAsyncOperation<StorageFile>> GetFilesAsync()Public Function GetFilesAsync() As IAsyncOperation( Of StorageFile )

    Returns

    • When this method completes successfully, it returns a list (type IVectorView<T> ) of files that are represented by StorageFile objects.

  • GetFilesAsync(System.UInt32,System.UInt32)
    GetFilesAsync(System.UInt32,System.UInt32)
    GetFilesAsync(System.UInt32,System.UInt32)
    GetFilesAsync(System.UInt32,System.UInt32)

    Retrieves a list of files in a specified range.

    public IAsyncOperation<StorageFile>> GetFilesAsync(System.UInt32 startIndex,System.UInt32 maxNumberOfItems)public IAsyncOperation<StorageFile>> GetFilesAsync(System.UInt32 startIndex,System.UInt32 maxNumberOfItems)Public Function GetFilesAsync(startIndex As System.UInt32,maxNumberOfItems As System.UInt32) As IAsyncOperation( Of StorageFile )

    Parameters

    • startIndex
      System.UInt32
      System.UInt32
      System.UInt32
      System.UInt32

      The zero-based index of the first file to retrieve. This parameter is 0 by default.

    • maxNumberOfItems
      System.UInt32
      System.UInt32
      System.UInt32
      System.UInt32

      The maximum number of files to retrieve. Use -1 to retrieve all files. If the range contains fewer files than the max number, all files in the range are returned.

    Returns

    • When this method completes successfully, it returns a list (type IVectorView<T> ) of files that are represented by StorageFile objects.

    Remarks

    Use this overload to improve system performance by presenting a virtualized view of the query results that includes only the necessary subset of files. For example, if your app displays many files in a gallery you could use this range to retrieve only the files that are currently visible to the user.

  • GetItemCountAsync()
    GetItemCountAsync()
    GetItemCountAsync()
    GetItemCountAsync()

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

    public IAsyncOperation<uint> GetItemCountAsync()public IAsyncOperation<uint> GetItemCountAsync()Public Function GetItemCountAsync() As IAsyncOperation( Of uint )

    Returns

    • When this method completes successfully, it returns the number of files in the location that match the query.

  • GetMatchingPropertiesWithRanges(Windows.Storage.StorageFile)
    GetMatchingPropertiesWithRanges(Windows.Storage.StorageFile)
    GetMatchingPropertiesWithRanges(Windows.Storage.StorageFile)
    GetMatchingPropertiesWithRanges(Windows.Storage.StorageFile)

    Gets matching file properties with corresponding text ranges.

    public IMap<TextSegment>> GetMatchingPropertiesWithRanges(Windows.Storage.StorageFile file)public IMap<TextSegment>> GetMatchingPropertiesWithRanges(Windows.Storage.StorageFile file)Public Function GetMatchingPropertiesWithRanges(file As Windows.Storage.StorageFile) As IMap( Of TextSegment )

    Parameters

    Returns

    • The matched properties and corresponding text ranges.

    Remarks

    Use this method to implement hit highlighting in your app's query results.

Events

  • ContentsChanged
    ContentsChanged
    ContentsChanged
    ContentsChanged

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

    public event TypedEventHandler ContentsChangedpublic event TypedEventHandler ContentsChangedPublic Event ContentsChanged

    Remarks

    If you register a handler for this event, keep that handler registered while you suspend your app (in response to oncheckpoint or Suspending ). Your app will not receive ContentsChanged events while it is suspended and when your app resumes it will receive a single event that aggregates all of the changes if any occurred.

    Additionally, keep in mind that registering and removing event handlers are synchronous operations and might cause your app to stop responding briefly if you execute them on your app's UI thread. Wherever possible, use a thread other than your app's UI thread to register and unregister these event handlers.

  • OptionsChanged
    OptionsChanged
    OptionsChanged
    OptionsChanged

    Fires when the query options change.

    public event TypedEventHandler OptionsChangedpublic event TypedEventHandler OptionsChangedPublic Event OptionsChanged

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ContractVersionAttribute

Details

Assembly

Windows.Storage.Search.dll