gpt4 book ai didi

c# - UWP c# 如何获取应用程序下载文件夹的 StorageFolder 对象

转载 作者:行者123 更新时间:2023-11-30 16:45:05 26 4
gpt4 key购买 nike

我正在使用 DownloadsFolder 方法创建文件和文件夹。

我想获取父文件夹作为 StorageFolder 实例,这样我就可以列出和操作应用下载文件夹中的所有项目。

我已经从已知的 StorageFile 中尝试了 GetParentAsync(),但返回值为空。

StorageFile sf = await DownloadsFolder.CreateFileAsync("testMarker");
StorageFolder dlFolder = await sf.GetParentAsync();

有什么方法可以编程访问这个文件夹吗?

最佳答案

您的应用似乎没有读取下载目录的权限。我们可以使用 GetParentAsync 获取应用程序对其有权限的父级,但不能获取应用程序没有权限的文件夹。

如果我们将音乐库、图片库和视频库添加到 appxmanifest 的功能中,我们可以使用 GetParentAsync 方法将父文件夹作为 StorageFolder在这些文件夹中。

If you create a file or folder in the Downloads folder, we recommend that you add that item to your app's FutureAccessList so that your app can readily access that item in the future.

更多信息,请引用Locations Windows Store apps can access .

因此,如果你想获取 DownloadsFolder 中的其他文件夹和文件,你应该能够 Open files and folders with a picker .

关于c# - UWP c# 如何获取应用程序下载文件夹的 StorageFolder 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42816659/

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