2015-04-08 101 views
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); 
     } 

回答

1

如果它抛出了“System.NotImplementedException”,那么它是不是在你的当前目标环境中可用的(有点很烂,但你会发现,他们离开了Windows.winmd的几件事情,可能是因为时间的限制)

如何过,你可以用获得的文件列表从StorageFolder

StorageFolder.GetFilesAsync(); 

的正常方式根据文档,你甚至可以通过你的OrderByDate到它

StorageFolder.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.OrderByDate); 

或者你可以自己排序IList<StorageFile>它不应该太难。

MSDN: StorageFolder.GetFilesAsync(CommonFileQuery) | getFilesAsync(CommonFileQuery) method

+0

感谢您的回复。我尝试了建议的代码,但得到'System.ArgumentOutOfRangeException'行StorageFolder.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.OrderByDate); – AbsoluteSith

+0

好吧我尝试了一些像等待KnownFolders.PicturesLibrary.GetFilesAsync(CommonFileQuery.OrderByDate); ,它很棒。但是当我在PicturesLibrary中选择一个特定的文件夹并尝试使用相同的代码时,它会给我一个'System.ArgumentOutOfRangeException'。任何线索如何摆脱这一点? – AbsoluteSith

+0

@AbsoluteSith是的,你需要使用'async'和'await'调用你所做的一切。对于默认文件夹,我认为您需要确保您在清单中正确设置了权限。至于子文件夹,我认为你需要让用户先选择文件夹,我敢肯定你不能直接访问它。查找遍历windows phone下的子文件夹,并首先在本地资源文件夹中尝试它,您可以访问它们。 –

相关问题