我在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
会拒绝访问?
是因为安全原因还是我在这里写错了什么?
答案 0 :(得分:15)
应用程序的安装目录是只读位置。此外,不建议您将数据文件写入已安装的位置。如果您需要存储数据,这仅供应用程序使用,您应该使用
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
或
Windows.Storage.StorageFolder temporaryFolder = ApplicationData.Current.TemporaryFolder;
取决于数据的生命周期。