nimbudew
nimbudew

Reputation: 978

ArgumentException while passing CommonFileQuery to StorageFolder.GetFilesAsync()

I'm trying to read a set of StorageFile from a StorageFolder using the GetFilesAsync() method in Windows Phone 8.1 RT.
The method works fine if only files are to be retrieved, but throws an ArgumentException when any CommonFileQuery is passed to sort the files.
I want to retrieve the files sorted by creation date, so I pass CommonFileQuery.OrderByDate, but I get the following stacktrace:

Value does not fall within the expected range.
at Windows.Storage.StorageFolder.GetFilesAsync(CommonFileQuery query)
at FileGetters.FileGetterMethods.<GetMyFilesAsync>d__19.MoveNext()

How can I get a sorted list of all the files present in the particular folder ordered by date?

Upvotes: 1

Views: 156

Answers (1)

Florian-Rh
Florian-Rh

Reputation: 797

sorry to tell you that apparently, CommonFileQuery can only be used for Library Folders.

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

Source: MSDN.com

Library Folders can be accessed using the class KnownFolders (see here)

But here is what you CAN do:

IEnumerable<StorageFile> files = await myFolder.GetFilesAsync();
IOrderedEnumerable<StorageFile> orderedFiles = files.OrderBy(f => f.DateCreated);

Upvotes: 1

Related Questions