CreateFileQuery(CommonFileQuery) | createFileQuery(CommonFileQuery) method
Collapse the table of content
Expand the table of content

StorageFolder.CreateFileQuery(CommonFileQuery) | createFileQuery(CommonFileQuery) method

Gets a query result object that contains the files in the current folder. Also gets the files from the subfolders of the current folder when the value of the query argument is something other than CommonFileQuery.DefaultQuery. Files are sorted based on the specified CommonFileQuery.


var storageFileQueryResult = storageFolder.createFileQuery(query);



Type: CommonFileQuery

One of the enumeration values that specifies how to sort the files and determines whether the query is shallow or deep.

Return value

Type: StorageFileQueryResult

A query result object. Call the GetFilesAsync method of the query result to get the flat list of files, sorted as specified by query. This method returns a list of type IReadOnlyList<StorageFile>. Each file is represented by an item of type StorageFile.



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.


A CommonFileQuery sorts files based on specific file attributes (like title or date) quickly and easily.

When you specify the DefaultQuery option from the CommonFileQuery enumeration, this query is a shallow query that returns only files in the current folder. When you specify another value from the CommonFileQuery enumeration, this query is a deep query that returns a flattened list of files from the current folder and from its subfolders.


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.

To get deep query results from a folder that's not a library folder, call the CreateFileQueryWithOptions(QueryOptions) method and specify Deep as the value of the FolderDepth property of the QueryOptions.

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

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 specify additional query options, call the CreateFileQueryWithOptions method.

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

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


The following example shows how to get the files in the user's Pictures folder and its subfolders, sorted by date, by calling the CreateFileQuery(CommonFileQuery) method.

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

// Get the user's Pictures folder.
// Enable the corresponding capability in the app manifest file.
var KnownFolders = Windows.Storage.KnownFolders;
var picturesFolder = KnownFolders.picturesLibrary;

// Get the files in the user's Pictures folder and sort them by date.
var CommonFileQuery = Windows.Storage.Search.CommonFileQuery;
var results = picturesFolder.createFileQuery(CommonFileQuery.orderByDate);

// Iterate over the results and print the list of files
// to the Visual Studio Output window.
var sortedFilesPromise = results.getFilesAsync();
sortedFilesPromise.done(function getFilesSuccess(sortedFiles) {
    sortedFiles.forEach(function forEachFile(item) {
        console.log(, item.dateCreated);

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 [C++]



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

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8


Windows::Storage [C++]



See also




© 2016 Microsoft