Question

Question

If the user gives my app a file using the FileOpenPicker, is it possible to and if it is possible, how do I keep a reference to that across the shutdown in the application life cycle?

Issues

I can't use the programmatic access given by the capabilities, since the file could (and is likely) to be opened from locations other than the folders capabilities gives access to.

Example of this

I am building a text file editor and I can save the content on suspend and restore it on start, that is not the issue. The issue is the user opens the file and can hit save at any point to save without a prompt, as I keep a reference to the StorageFile as in a private field. If the application shuts down, there seems to be no way to get that StorageFile again without prompting the user.

Windows Store app Details

Life cycle

In a Windows Store app, the app will be suspended when the user moves away from the app and if there is memory pressures on the machine, it will be shut down. The pattern is to save on suspend (since there is no way to handle shutdown) and then resume on next start by loading the data saved.

Reading data from files

In a Windows store app, there are two ways to access files - either you get the user to give you the file with the FileOpenPicker or you can opt-in to the capabilities which gives some programmatic access to some folders.

Était-ce utile?

La solution

You can use this solution : http://www.jonathanantoine.com/2012/08/06/keep-access-to-filesfolders-the-user-granted-you/

Store it in the FutureAccessList:

var picker = new FolderPicker();
picker.FileTypeFilter.Add("*");
var folder = await picker.PickSingleFolderAsync();

StorageApplicationPermissions.FutureAccessList.AddOrReplace(Token, folder);

And get it back :

var folder = await StorageApplicationPermissions
    .FutureAccessList.GetFolderAsync(Token);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top