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 中创建文件异步时访问被拒绝?


- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 输入按键事件处理程序 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01