且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Windows应用商店应用启动时自动加载以前使用的文件

更新时间:2023-10-13 15:06:04

你不能从路径中重构任意的访问。您需要挂上StorageFile以保持其访问权限。要缓存跨会话,请使用Windows.Storage.AccessCache类,例如StorageApplicationPermissions.FutureAccessList和MostRecentlyUsedList。

这些将允许您保存选择器授予的权限应用程序重新启动。



我将在 http://blogs.msdn.com/b/wsdevsol/archive/2012/12/05/stray -from-the-path-stick-to-the-storagefile.aspx

I've come across a scenario in my Windows Store app development that various websites indicate is not possible. Can someone please confirm if the following is possible in a Windows Store app and how it can be done programmatically?

  • User taps on a "Load File" button to load a document, is presented with the standard Metro FilePicker, selects a document, and the file loads into the application for editing. The application somehow saves the path to this file or some other resource that would allow the file to be automatically opened on a future application start.
  • User restarts the application by closing it and then opening it.
  • On startup, the application loads the most recently opened document and automatically presents the user with it for editing again (without having to present the user with another FilePicker). The user makes changes to the document, hits Control + S on the keyboard, and changes are automatically saved to the file.

I have tried this in my current application, but it seems that loading a file path automatically from OneDrive does not work (I get a System.UnauthorizedAccessException: Access is denied.). Online, I've read that including the documents capability (which would allow me access to my OneDrive file) will not allow my application to get approval, and since I need approval, this is not a possibility for me.

You cannot reconstitute arbitrary for access from a path. You need to hang on to the StorageFile to keep its access. To cache the across sessions use the Windows.Storage.AccessCache classes such as StorageApplicationPermissions.FutureAccessList and MostRecentlyUsedList.

These will let you save the permissions granted by the picker to reuse when the app restarts.

I discuss this in more detail at http://blogs.msdn.com/b/wsdevsol/archive/2012/12/05/stray-from-the-path-stick-to-the-storagefile.aspx