locked
A exception is happen when calling GetFilesAsync with parameter of CommonFileQuery.OrderByDate. RRS feed

  • Question

  • A exception is happen when calling GetFilesAsync with parameter of CommonFileQuery.OrderByDate.

    this is my code and exception.

    ------------------------------------------------------Exception--------------------------------------------------------------------

       

    A first chance exception of type 'System.ArgumentException' occurred in Apps.WindowsPhone.exe
    System.ArgumentException: Value does not fall within the expected range.
       at Windows.Storage.StorageFolder.GetFilesAsync(CommonFileQuery query)
       at Apps.RecentDevManger.<RemoveOldestDev>d__0.MoveNext()
    -------------------------------------------------------------------------------------------------------------------------------------------------

    --------------------------------------------------------Code-------------------------------------------------------------------

                    

    try
    {
    StorageFolder LocalFolder = ApplicationData.Current.LocalFolder;

    StorageFolder Folder = await LocalFolder.CreateFolderAsync("test", CreationCollisionOption.OpenIfExists);


    IReadOnlyList<StorageFile> FileList =

    await Folder.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.OrderByDate);

    return FileList;
    }
    catch(Exception e)
    {
    Debug.WriteLine(e.ToString());
    return null;
    }

    ----------------------------------------------------------------------------------------------------------------------------------------------------------


    Tuesday, November 25, 2014 1:16 AM

Answers

  • Hi estmob,

    We can only use the CommonFileQuery.OrderByDate option for the folders in a library or the HomeGroup folder, but we can use the CommonFileQuery.DefaultQuery option with any storage location. And I have tested your example, it works very well with the CommonFileQuery.DefaultQuery.

    For more information, please try to refer to the following article:
    #CommonFileQuery enumeration:
    http://msdn.microsoft.com/library/windows/apps/br207956 .

    Then if we want to access the file in the PicturesLibrary, we can useCommonFileQuery.OrderByDate as the following code:

     try
     {
      StorageFolder MyPicturesFolder = KnownFolders.PicturesLibrary;
      IReadOnlyList<StorageFile> FileList = await MyPicturesFolder.GetFilesAsync(CommonFileQuery.OrderByDate);
      return FileList;  
     }
    catch(Exception e)
     {
      Debug.WriteLine(e.ToString());
      return null;
     }
     

    Best Regards,
    Amy Peng

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, November 25, 2014 8:02 AM