StorageFolderQueryResult class

StorageFolderQueryResult class

Provides access to the results of a query that lists the folder (or file groups) in the folder being queried (which is represented by a storageFolder). You can use a storageFolderQueryResult to enumerate folders or file groups in that folder.


var storageFolderQueryResult = storageFolder.createFolderQuery();


The StorageFolderQueryResult class has these types of members:


The StorageFolderQueryResult class has these events.

ContentsChanged Fires when a file is added to, deleted from, or modified in the folder being queried.
OptionsChanged Fires when the query options change.



The StorageFolderQueryResult class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

ApplyNewQueryOptions Modifies query results based on new QueryOptions.
FindStartIndexAsync Retrieves the index of the folder from the query results that most closely matches the specified property value. 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.
GetFoldersAsync() Retrieves a list of all the folders (or file groups) in the result set.
GetFoldersAsync(UInt32, UInt32) Retrieves folders (or file groups) in a specified range.
GetItemCountAsync Retrieves the number of folders (or file groups) in the set of query results.



The StorageFolderQueryResult class has these properties.

PropertyAccess typeDescription



Gets the folder originally used to create the StorageFolderQueryResult object.



Note  Although it's not attributed with marshalling_behavior(agile), this class can be treated as agile. For more info, see Threading and Marshaling (C++/CX).

You can get a storageFolderQueryResult object by calling the following methods from a storageFolder or a folderInformation object:

For more code examples that show you how to use storageFolderQueryResult objects, see the Folder enumeration sample.

To get a StorageFolderQueryResult object to enumerate the folders or file groups in a location, you must get a storageFolder that represents the location and then create a folder query


This example demonstrates how to get a list folders (or file groups) from a storageFolderQueryResult object.

// Get the Pictures library, then rearrange it by month
var picturesLibrary = Windows.Storage.KnownFolders.picturesLibrary;

// Set query options to create groups of files within result
var queryOptions = new QueryOptions(Windows.Storage.Search.CommonFolderQuery.GroupByMonth);

// Create query and retrieve result
var queryResult = picturesLibrary.createFolderQuery(Windows.Storage.Search.CommonFolderQuery.groupByMonth);
queryResult.getFoldersAsync().done(function(folders) {
    // Process file groups (or folders)

    // Create an array of promises that will asynchronously
    // retrieve the files for each file group
    var promises = (folder) {
        return folder.getFilesAsync();

    // Aggregate the results of multiple asynchronous operations
    // so that they are returned after all are completed. This
    // ensures that the groups are displayed in order.
    WinJS.Promise.join(promises).done(function (folderContents) {
        // Process the contents of each file group (or folder)

        for (var i in folderContents) {
            // Process the group/folder at index i of folderContents

            // Display the group name
            var group = outputResultGroup(folders.getAt(i).name);
            // Display the items in the group 
            outputItems(group, folderContents[i]);

The queryResult variable gets the storageFolderQueryResult that is used to retrieve file groups (or folders) 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.

Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0


Windows::Storage::Search [C++]



Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows 10 Mobile


Windows::Storage::Search [C++]





See also

Windows.Storage.storageFolder.createFolderQuery methods
Windows.Storage.storageFolder.createFolderQueryWithOptions method
Windows.Storage.BulkAccess.folderInformation.createFolderQuery methods
Windows.Storage.BulkAccess.folderInformation.createFolderQueryWithOptions method
Folder enumeration sample (Windows 10)



© 2016 Microsoft