我在我的应用中使用FilePicker让用户选择一个文件。但是下次应用程序运行时,用户必须以这种方式再次打开它。我想提供打开最近文件的可能性。这可能吗?
答案 0 :(得分:4)
您可以使用FutureAccessList
课程来完成此操作。这是一种记住打开的文件和/或文件夹的机制。您必须自己分配一个令牌,以使其在您的应用中独一无二,但您可以使用Guid.NewGuid().ToString()
使其独一无二。
要记住文件,您可以使用以下方法:
public string RememberFile(StorageFolder file)
{
string token = Guid.NewGuid().ToString();
StorageApplicationPermissions.FutureAccessList.AddOrReplace(token, file);
return token;
}
To retrieve the file the next time, you can use this:
public async Task<StorageFile> GetFileForToken(string token)
{
if (!StorageApplicationPermissions.FutureAccessList.ContainsItem(token)) return null;
return await StorageApplicationPermissions.FutureAccessList.GetFileAsync(token);
}
To forget a token, you can use this:
public async Task<StorageFile> GetFileForToken(string token)
{
if (!StorageApplicationPermissions.FutureAccessList.ContainsItem(token)) return null;
return await StorageApplicationPermissions.FutureAccessList.GetFileAsync(token);
}
您可以使用此机制存储带有文件名的令牌列表。这样,您可以为用户提供文件的线索,并有办法再次打开它。
答案 1 :(得分:0)
您无法直接从路径访问代理文件,因此保存它的价值不大。 FileOpenPicker是您访问的权限,它仅限于它返回的特定文件。您的所有应用都可以显式为FileOpenPicker上的SuggestedStartLocation
属性。
该应用可以使用Windows.Storage.AccessCache
来记住您通过FileOpenPicker获得访问权限的项目。特别参见StorageItemMostRecentlyUsedList。