加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 尝试在InstalledLocation StorageFolder中创建文件同步时

发布时间:2020-12-15 03:53:40 所属栏目:百科 来源:网络整理
导读:尝试在InstalledLocation StorageFolder中CreateFileAsync时,我的Access被拒绝 StorageFolder storageFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;StorageFile file = await storageFolder.CreateFileAsync("fileNmae",Windows.St
尝试在InstalledLocation StorageFolder中CreateFileAsync时,我的Access被拒绝
StorageFolder storageFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFile file = await storageFolder.CreateFileAsync("fileNmae",Windows.Storage.CreationCollisionOption.ReplaceExisting);

我也试过

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

并且“价值不在预期范围内”

我可以在Windows.Storage.ApplicationData.Current.LocalFolder中创建CreateFileAsync,然后将CopyAsync复制到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允许Access被拒绝?
那是因为安全原因还是我在这里编码错了?

解决方法

该应用的安装目录是只读位置.另外,不建议您将数据文件写入安装位置.如果您需要存储数据,仅供应用程序使用,您应该使用
StorageFolder localFolder = ApplicationData.Current.LocalFolder;

要么

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

取决于数据的生命周期.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读