尝试在 InstalledLocation StorageFolder 中创建文件异步时访问被拒绝?

Access is denied when trying to CreateFileAsync in InstalledLocation StorageFolder?(尝试在 InstalledLocation StorageFolder 中创建文件异步时访问被拒绝?)
本文介绍了尝试在 InstalledLocation StorageFolder 中创建文件异步时访问被拒绝?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 InstalledLocation StorageFolder 中尝试 CreateFileAsync 时访问被拒绝

I got Access is denied when trying to CreateFileAsync in InstalledLocation StorageFolder

StorageFolder storageFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFile file = await storageFolder.CreateFileAsync("fileNmae", Windows.Storage.CreationCollisionOption.ReplaceExisting);

我也试过了

var storageFolder = await StorageFolder.GetFolderFromPathAsync("ms-appx:///");

并得到值不在预期范围内"

And got "value does not fall within the expected range"

我可以在 Windows.Storage.ApplicationData.Current.LocalFolder 中进行 CreateFileAsync 然后 CopyAsync 到 InstalledLocation StorageFolder?

I can go around and CreateFileAsync in Windows.Storage.ApplicationData.Current.LocalFolder then CopyAsync to InstalledLocation StorageFolder?

StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
StorageFile file = await storageFolder.CreateFileAsync("fileName", Windows.Storage.CreationCollisionOption.ReplaceExisting);

StorageFolder installedLocationFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
var result = await file.CopyAsync(installedLocationFolder, "fileName", Windows.Storage.NameCollisionOption.ReplaceExisting);

但是 InstalledLocation StorageFolder 中的 CreateFileAsync 会拒绝访问?是因为安全原因还是我在这里编码错误?

but CreateFileAsync in InstalledLocation StorageFolder gives Access denied ? is that because of security reason or I'm coding something wrong here?

推荐答案

应用的安装目录为只读位置.此外,不建议您将数据文件写入安装位置.如果您需要存储仅供应用程序使用的数据,您应该使用

The app's install directory is a read-only location. In addition, it would not be recommended that you write data files to the installed location. If you need to store data this is for the application's use only, you should use

StorageFolder localFolder = ApplicationData.Current.LocalFolder;

Windows.Storage.StorageFolder temporaryFolder = ApplicationData.Current.TemporaryFolder;

取决于数据的生命周期.

depending on the lifetime of the data.

这篇关于尝试在 InstalledLocation StorageFolder 中创建文件异步时访问被拒绝?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)