Windows 10 个文件查询问题

Windows 10 FIle query issues

我正在尝试按照说明从 windows 10 中的已知文件夹中获取文件,如下所示,

https://msdn.microsoft.com/en-us/library/windows/apps/br227275.aspx

            try
            {
                StorageFolder folder = KnownFolders.PicturesLibrary;
                IReadOnlyList<StorageFile> pics = await folder.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.OrderByDate, 0, 20);
                Debug.WriteLine(pics.Count);
            }

            catch(Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

相同的代码适用于 WindowsPhone 8.1 SDK。但在 Windows 10 手机上却没有。我得到的例外是,

The specified query options are not available for this folder because it is not within a library or Homegroup. Only folders within a library or a Homegroup support all options.

关于如何解决这个问题有什么想法吗?

Windows 10 移动版与 Windows 10 桌面版相同。来自 MSDN 的示例代码:

尝试使用没有 try catch 块的代码。另外,请注意这是使用异步编程技术。

您需要赋予图片库访问图片并从中关联信息的能力。

进入您应用程序的解决方案资源管理器 >> 然后 "Package.appxmanifest" >> 然后 "Capabilities" >> Select "Pictures Library"(如果它不是 selected 然后 select 它)。

重建您的项目后,您可以运行 成功地编写您的代码。 希望这对你有帮助:-)

更新了答案,下面的代码有效,经过测试

StorageFolder folder = KnownFolders.PicturesLibrary;
StorageFileQueryResult query = folder.CreateFileQuery(Windows.Storage.Search.CommonFileQuery.OrderByDate);
IReadOnlyList<StorageFile> pics = await query.GetFilesAsync(0, 20);
Debug.WriteLine(pics.Count);

MSDN 上有一个获取文件夹查询的示例,同样适用于文件查询 https://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj150593.ASP

Windows10还在工作中。 phone 上的最新版本解决了这个问题。