1
我正在开发一个基于Windows Phone 8.1(RT)的项目,我想根据创建日期显示文件列表。当我尝试从这个link的代码,我得到一个'System.NotImplementedException'。获取在Windows Phone 8.1中按日期排序的文件
而且我的智能感知提示我,它没有在Windows Phone 8.1中实现。那么这是否意味着我不能使用查询选项或有没有其他的选择? 代码:
StorageFolder picturesFolder = KnownFolders.PicturesLibrary;
// Get the files in the user's Pictures folder and sort them by date.
StorageFileQueryResult results =
picturesFolder.CreateFileQuery(CommonFileQuery.OrderByDate);
// Iterate over the results and print the list of files
// to the Visual Studio Output window.
IReadOnlyList<StorageFile> sortedFiles =
await results.GetFilesAsync();
foreach (StorageFile item in sortedFiles)
{
Debug.WriteLine(item.Name + ", " + item.DateCreated);
}
感谢您的回复。我尝试了建议的代码,但得到'System.ArgumentOutOfRangeException'行StorageFolder.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.OrderByDate); – AbsoluteSith
好吧我尝试了一些像等待KnownFolders.PicturesLibrary.GetFilesAsync(CommonFileQuery.OrderByDate); ,它很棒。但是当我在PicturesLibrary中选择一个特定的文件夹并尝试使用相同的代码时,它会给我一个'System.ArgumentOutOfRangeException'。任何线索如何摆脱这一点? – AbsoluteSith
@AbsoluteSith是的,你需要使用'async'和'await'调用你所做的一切。对于默认文件夹,我认为您需要确保您在清单中正确设置了权限。至于子文件夹,我认为你需要让用户先选择文件夹,我敢肯定你不能直接访问它。查找遍历windows phone下的子文件夹,并首先在本地资源文件夹中尝试它,您可以访问它们。 –