我想将文件下载到Downloads
文件夹并阅读。它是一个像照片和视频的根文件夹。
但是Windows.Storage.DownloadsFolder
无法用于手机,我在KnownFolders
中看不到Windows.Storage.KnownFolders.PicturesLibrary;
此外,我尝试C:\Data\Users\Public\Downloads\
它会产生未经授权的结果。
我看到有些应用可以访问它,但是怎么样?
答案 0 :(得分:7)
您可以使用文件或文件夹选择器。 我不确定您是否希望用户选择文件,或者您想自己选择文件,但我认为实现此目的的最佳方法是使用以下内容:
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.SuggestedStartLocation = PickerLocationId.Downloads;
StorageFile file = await openPicker.PickSingleFileAsync();
或
FolderPicker folderPicker = new FolderPicker();
folderPicker.SuggestedStartLocation = PickerLocationId.Downloads;
folderPicker.PickFolderAndContinue();
答案 1 :(得分:2)
要完成上一个答案,可以访问此类文件夹,但只能在首次通过FolderPicker访问后才能访问。
诀窍是使用StorageApplicationPermissions.FutureAccessList。这是文件资源管理器应用程序的功能。它会为您提供一个可以保存在IsolatedStorage中的令牌,因此您可以稍后直接访问Downloads文件夹,这要归功于令牌。
请参阅StorageApplicationPermissions.mostRecentlyUsedList:http://msdn.microsoft.com/library/windows/apps/hh972603的演练,但FutureAccessList的原理完全相同。