2015-04-08 102 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下的子文件夾,並首先在本地資源文件夾中嘗試它,您可以訪問它們。 –

相關問題