gpt4 book ai didi

uwp - 我可以记住在 UWP 应用程序中打开的文件吗?

转载 作者:行者123 更新时间:2023-12-04 01:17:56 25 4
gpt4 key购买 nike

我在我的应用程序中使用 FilePicker 让用户选择一个文件。但是下次应用程序运行时,用户必须以这种方式再次打开它。我想提供打开最近文件的可能性。这可能吗?

最佳答案

您可以使用 FutureAccessList 类来做到这一点。这是一种记住打开的文件和/或文件夹的机制。您必须自己分配 token 以使其在您的应用程序中独一无二,但您可以使用 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);
}

您可以使用此机制来存储带有文件名的 token 列表。通过这种方式,您可以为用户提供文件线索,并有办法再次打开它。

关于uwp - 我可以记住在 UWP 应用程序中打开的文件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38103655/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com