Udostępnij za pośrednictwem


StorageFolderQueryResult Class

Definition

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.

public ref class StorageFolderQueryResult sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
class StorageFolderQueryResult final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
public sealed class StorageFolderQueryResult
Public NotInheritable Class StorageFolderQueryResult
Inheritance
Object Platform::Object IInspectable StorageFolderQueryResult
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 folders (or file groups) from a StorageFolderQueryResult object.

// Get the Pictures library
Windows.Storage.StorageFolder picturesLibrary = Windows.Storage.KnownFolders.PicturesLibrary;

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

// Create query and retrieve result
StorageFolderQueryResult queryResult = picturesLibrary.CreateFolderQueryWithOptions(queryOptions);
IReadOnlyList<StorageFolder> folders = await queryResult.GetFoldersAsync();
// Process file groups
foreach (StorageFolder folder in folders)
{
    // Get and process files in group
    IReadOnlyList<StorageFile> fileList = await folder.GetFilesAsync();
    OutputPanel.Children.Add(CreateHeaderTextBlock(folder.Name + " (" + fileList.Count + ")"));
    foreach (StorageFile file in fileList)
    {
        // Process file
    }
}

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.

Remarks

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.

Properties

Folder

Gets the folder originally used to create the StorageFolderQueryResult 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 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.

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