本文介绍了尝试在 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 中创建文件异步时访问被拒绝?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 22:24