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

标签 c# win-universal-app uwp windows-10-universal

我在运行我的 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/

相关文章:

c# - 使用 Entity Framework 4 执行自定义 sql

xaml - 未检测到已安装的组件。无法解析 TargetName HighContrastBorder - UWP Windows 10

c# - 将录制的声音保存到 UWP 中的项目文件

CSS 与 XAML 测量

windows - UWP package.appmanifest Assets 生成器扩展了我的图像

c# - 'MyClass' 的类型初始值设定项抛出异常

c# - 字符串表现得像一个值类型

c# - 从 C# 中具有相同主键的两个表中获取不同的列值

visual-studio - UWP - SignTool 错误 : No certificates were found that met all the given criteria

c# - 你可以从它的路径访问一个选择的 StorageFile 吗? - UWP