Windows Dev Center

StorageFolder.CreateFileQuery() | createFileQuery() method

Gets a query result object that contains the files in the current folder.

Syntax


public StorageFileQueryResult CreateFileQuery()

Parameters

This method has no parameters.

Return value

Type: StorageFileQueryResult

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

Remarks

This query is a shallow query that returns only files in the current folder. For a list of methods that identifies shallow queries and deep queries, see the Remarks in the topic GetFilesAsync.

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.

Examples

The following example gets a query result object that contains the files in the current folder by calling the CreateFileQuery() method.


using Windows.Storage;
using Windows.Storage.Search;
using System.Threading.Tasks;
using System.Diagnostics; // For writing results to Output window.
...
            // Get the app's installation folder.
            StorageFolder appFolder =
                Windows.ApplicationModel.Package.Current.InstalledLocation;

            // Get the files in the current folder.
            StorageFileQueryResult results = appFolder.CreateFileQuery();

            // Iterate over the results and print the list of files
            // to the Visual Studio Output window.
            IReadOnlyList<StorageFile> filesInFolder =
                await results.GetFilesAsync();
            foreach (StorageFile item in filesInFolder)
            {
                Debug.WriteLine(item.Name);
            }


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(CommonFileQuery)
CreateFileQueryWithOptions

 

 

Show:
© 2015 Microsoft