Access is denied when trying to CreateFileAsync in 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 中创建文件异步时访问被拒绝?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:尝试在 InstalledLocation StorageFolder 中创建文件异步时访问被拒绝?


基础教程推荐
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01