问题
I want to download files to Downloads
folder and read. it is a root folder like photos and videos.
But Windows.Storage.DownloadsFolder
isn't available for phone and I don't see it in KnownFolders
like Windows.Storage.KnownFolders.PicturesLibrary;
Also I tried C:\Data\Users\Public\Downloads\
it gives an unauthorized result.
I see some apps has access to it, but how?
回答1:
You can use a file or folder picker. I'm not sure if you want the user to chose a file, or if you want to pick a file yourself, but i think the best way to achieve this is using something like:
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.SuggestedStartLocation = PickerLocationId.Downloads;
StorageFile file = await openPicker.PickSingleFileAsync();
or
FolderPicker folderPicker = new FolderPicker();
folderPicker.SuggestedStartLocation = PickerLocationId.Downloads;
folderPicker.PickFolderAndContinue();
回答2:
To complete the previous answer, it is possible to access such a folder, but only after a first access to it through FolderPicker.
The trick is to use the StorageApplicationPermissions.FutureAccessList. It is what file explorers applications do. It will give you a token that you can save in your IsolatedStorage, so you can later access the Downloads folder directly, thanks to the token.
See there for a walkthrough with StorageApplicationPermissions.mostRecentlyUsedList : http://msdn.microsoft.com/library/windows/apps/hh972603 but the principles are quite the same with FutureAccessList.
来源:https://stackoverflow.com/questions/23340398/how-to-access-downloads-folder-in-windows-phone-8-1