1

I have a simple writing app for Windows 8.1, which I'm currently expanding to include tabs. I am also adding an autosave feature to these tabs, so that when the user 'closes' the app, it writes the content of the file and the path, if its an existing file, to a txt file in the localstorage.

This works great when the files are unsaved. The user closes the app, and after reopening all his tabs are there again, with the latest changes.

The problem I have is when the file is already saved. I store the path in the txt, so I thought I'd just open the file again on opening of the app, but the problem is that I am not allowed to open just any file on the system. The user could have opened a file from his C: drive, which I cannot read (for instance as described here).

Any ideas on how I could solve this. I'm afraid that what I'm trying to do will not be possible.

If needed I could show some code about saving the autosave file, but I didn't think I could show anything relevant to the question.

4

2 回答 2

3

正如 Vasile 所说,一旦应用程序关闭,您将无法访问沙盒之外的 StorageFile。

但是 WinRT 确实提供了StorageApplicationPermissions类,您可以在其中将这些权限存储到文件中。然后,您可以存储令牌以供后续启动应用程序。

于 2013-11-09T22:24:23.990 回答
1

这是因为应用程序是沙盒的,并且无法访问除 之外的其他存储区域,Local Storage除非您通过 Open picker 进行用户交互。

假设您将文件保存在C:\. 另外,将其保存Local Storage在应用程序上。下次,当应用程序加载时,选项卡中将显示来自 - 的文本文件Local Storage- 进行编辑,将其保存在 PC 中的某个位置并覆盖来自LocalStorage. 这样,您使用的文件实际上是本地存储中的文件。

你必须小心这里的命名。如果您保存SampleFile.txtC:\然后创建另一个也称为SampleFile.txtbut onD:\的文件,当您将文件复制到 中时 LocalStorage,它应该与第一个不同。在这里,您必须提出自己的规则。

于 2013-11-09T16:31:23.163 回答