gpt4 book ai didi

c# - 如何在 UWP 应用程序中创建文件夹?

转载 作者:太空狗 更新时间:2023-10-29 20:51:15 24 4
gpt4 key购买 nike

我在运行我的 UWP 应用程序时尝试创建。

我有以下代码:

string documentsPath = Package.Current.InstalledLocation.Path;
System.Threading.ManualResetEvent mre = new System.Threading.ManualResetEvent(false);
Task.Factory.StartNew(async () =>
{
await Package.Current.InstalledLocation.CreateFolderAsync("Data");
mre.Set();
});
mre.WaitOne();

但是行:

await Package.Current.InstalledLocation.CreateFolderAsync("Data");

抛出以下错误:

"Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"}

查看this link: UWP File access permissions它声明如下:

When you create a new app, you can access the following file system locations by default:

Application install directory. The folder where your app is installed on the user’s system.

There are two primary ways to access files and folders in your app’s install directory:

You can retrieve a StorageFolder that represents your app's install directory, like this:

Windows.Storage.StorageFolder installedLocation = Windows.ApplicationModel.Package.Current.InstalledLocation

所以我认为我的代码可以工作。所以我的问题是如何使用 UWP 应用程序创建文件夹?

最佳答案

您无法在 InstalledLocation 中创建文件夹,MSDN :

...The app's install directory is a read-only location...

尝试使用本地文件夹:

ApplicationData.Current.LocalFolder.CreateFolderAsync("Data");

关于c# - 如何在 UWP 应用程序中创建文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36550122/

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