Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

QueryOptions class

Applies to Windows only

Specifies the parameters of a search query for enumerating the contents of storage folders.

Syntax


var queryOptions = new Windows.Storage.Search.QueryOptions();
var queryOptions = new Windows.Storage.Search.QueryOptions(query);
var queryOptions = new Windows.Storage.Search.QueryOptions(query, fileTypeFilter);

Attributes

[MarshalingBehavior(Agile)]
[Version(0x06020000)]

Members

The QueryOptions class has these types of members:

Constructors

The QueryOptions class has these constructors.

ConstructorDescription
QueryOptions()
QueryOptions(CommonFileQuery, IIterable(String))
QueryOptions(CommonFolderQuery)

 

Methods

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

MethodDescription
LoadFromString
SaveToString
SetPropertyPrefetch
SetThumbnailPrefetch
StorageProviderIdFilter

 

Properties

The QueryOptions class has these properties.

PropertyAccess typeDescription

ApplicationSearchFilter

Read/write

DateStackOption

Read-only

FileTypeFilter

Read-only

FolderDepth

Read/write

GroupPropertyName

Read-only

IndexerOption

Read/write

Language

Read/write

SortOrder

Read-only

UserSearchFilter

Read/write

 

Remarks

You can create a file query for any folder you have access to and that you can get as a StorageFolder.

You can use QueryOptions and CreateFileQueryWithOptions to create an indexed backed file query that lets you get properties that rely on another app's property handler.

For more code examples that show you how to use QueryOptions, see the Folder enumeration sample and the File system search sample.

For more code samples about accessing properties, see the File access sample.

Examples

This example demonstrates how to use QueryOptions to query files in a location.



// 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 previous example relies on the Pictures library capability through PicturesLibrary to get a StorageFolder object. To learn more about accessing files and folders, see File access and permissions in Windows Store apps.

This example demonstrates how to use a file query that is backed by the system index to retrieve properties that may rely on another app's property handler (like Title document property).



// Create index backed file query and get results
var picturesLibrary = Windows.Storage.KnownFolders.picturesLibrary;
var fileTypeFilter = [".png"];
var queryOptions = new Windows.Storage.Search.QueryOptions(Windows.Storage.Search.CommonFileQuery.orderByName, fileTypeFilter);
queryOptions.indexerOption = Windows.Storage.Search.IndexerOption.onlyUseIndexer;
var fileQuery = picturesLibrary.createFileQueryWithOptions(queryOptions);
fileQuery.getFilesAsync().then(function (files) {
    // Process resulting files
    if (files.size === 0) {
        // Perform tasks to handle no files found
    } else {
        // Access properties for each file
        files.forEach(function (file) {
            // Get document properties
            file.properties.getDocumentPropertiesAsync().done(function (documentProperties) {
                // Perform tasks with document properties
                var title = documentProperties.title;
            });
        });
    }
},
// Handle errors with an error function
function (error) {
    // Handle errors encountered while processing files
});

The previous example relies on the Pictures library capability through PicturesLibrary to get a StorageFolder object. To learn more about accessing files and folders, see File access and permissions in Windows Store apps.

In the example, file contains a StorageFile that represents the file to retrieve properties for.

Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

None supported

Namespace

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

Metadata

Windows.winmd

 

 

Show:
© 2014 Microsoft