尝试在InstalledLocation StorageFolder中创建CreateFileAsync时访问被拒绝
StorageFolder storageFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFile file = await storageFolder.CreateFileAsync("fileNmae", Windows.Storage.CreationCollisionOption.ReplaceExisting);
我也试过了
var storageFolder = await StorageFolder.GetFolderFromPathAsync("ms-appx:///");
并得到“值不在预期范围内”
我可以四处走动,然后先将
CreateFileAsync
放入Windows.Storage.ApplicationData.Current.LocalFolder
中,然后再将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
提供了拒绝访问的权限?是出于安全原因还是我在此处编码错误?
最佳答案
该应用程序的安装目录是只读位置。另外,不建议您将数据文件写入安装位置。如果您需要存储数据仅供应用程序使用,则应使用
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
或者
Windows.Storage.StorageFolder temporaryFolder = ApplicationData.Current.TemporaryFolder;
取决于数据的生存期。