Windows Dev Center

Expand Minimize

StorageFolder.CreateFileQueryWithOptions | createFileQueryWithOptions method

Gets a query result object that contains the files in the current folder and, optionally, in the subfolders of the current folder. The results are based on the specified QueryOptions.

Syntax


Public Function CreateFileQueryWithOptions(
  queryOptions As QueryOptions 
) As StorageFileQueryResult

Parameters

queryOptions

Type: QueryOptions

The criteria that are applied to the query.

Return value

Type: StorageFileQueryResult

A query result object that contains the files in the current folder and, optionally, in the subfolders of the current folder, filtered and sorted based on the specified QueryOptions. Call the GetFilesAsync method of the query result to get the flat list of files, sorted as specified by queryOptions. This method returns a list of type IReadOnlyList<StorageFile>. Each file is represented by an item of type StorageFile.

Exceptions

ExceptionCondition
System.ArgumentException

You specified a value other than DefaultQuery from the CommonFileQuery enumeration for a folder that's not a library folder. Check the value of query.

Remarks

In the following cases, this query is a shallow query that returns only files in the current folder.

  • Default behavior of this method if none of the following options are specified.

    - or -

  • Specify DefaultQuery as the value of CommonFileQuery when you instantiate the QueryOptions object.

    - or -

  • Specify Shallow as the value of the FolderDepth property of the QueryOptions object.

In the following cases, this query is a deep query that returns files from the current folder and from its subfolders.

Note  

Some of the values from the CommonFileQuery enumeration can only be used with a library folder (such as the Pictures library) or the Homegroup folder. In addition to the DefaultQuery option, you can use only the OrderByName and OrderBySearchRank options with a folder that's not a library folder.

For a list of methods that identifies shallow queries and deep queries, see the Remarks in the topic GetFilesAsync.

To check whether the QueryOptions you want to specify are available for the current folder, call the folder's AreQueryOptionsSupported method. To check whether a specific CommonFileQuery is available, call the folder's IsCommonFileQuerySupported method.

You can also get a list of files in the current folder asynchronously by calling one of the GetFilesAsync methods.

To get a query result object that contains the files in the current folder without configuring a QueryOptions object, call one of the CreateFileQuery methods.

To get items that are files or folders, call the CreateItemQueryWithOptions method.

For Windows Server 2012:  You must install indexer components to use some QueryOptions because indexer components are not installed by default.

Examples

The following example shows how to get the JPG files in the user's Pictures folder and its subfolders, sorted by date, by calling the CreateFileQueryWithOptions(QueryOptions) method. This query is a deep query because the folder is a library folder and a value other than DefaultQuery from the CommonFileQuery enumeration is specified.

Before you run the following example, enable the Pictures Library capability in the app manifest file.

No code example is currently available or this language may not be supported.

Requirements (device family)

Device family

Universal

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

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

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (operating system)

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8

Namespace

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

Metadata

Windows.winmd

See also

StorageFolder
CreateFileQuery

 

 

Show:
© 2015 Microsoft