StorageFolder.GetFilesAsync(CommonFileQuery) | getFilesAsync(CommonFileQuery) method
Gets 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 value from the CommonFileQuery enumeration.
One of the enumeration values that specifies how to sort the files and determines whether the query is shallow or deep.
When this method completes successfully, it returns a flat list of files, sorted as specified by query. The list is of type IReadOnlyList<StorageFile>. Each file in the list is represented by a StorageFile object.
You don't have permission to access the contents of the current folder.
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 specify additional query options, call the CreateFileQueryWithOptions method.
To get items that are files or folders, call the GetItemsAsync method.
The following example shows how to get the contents of the user's Pictures folder and its subfolders, sorted by date, by calling the GetFilesAsync(CommonFileQuery) method.
Before you run the following example, enable the Pictures Library capability in the app manifest file.
using Windows.Storage; using Windows.Storage.Search; using System.Threading.Tasks; using System.Diagnostics; // For writing results to Output window. ... // Get the user's Pictures folder. // Enable the corresponding capability in the app manifest file. StorageFolder picturesFolder = KnownFolders.PicturesLibrary; // Get the files in the current folder, sorted by date. IReadOnlyList<StorageFile> sortedItems = await picturesFolder.GetFilesAsync(CommonFileQuery.OrderByDate); // Iterate over the results and print the list of files // to the Visual Studio Output window. foreach (StorageFile file in sortedItems) Debug.WriteLine(file.Name + ", " + file.DateCreated);
Minimum supported client
Minimum supported server
|Windows Server 2012|
Minimum supported phone
|Windows Phone 8|