9

我在 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进入InstalledLocation StorageFolder吗?Windows.Storage.ApplicationData.Current.LocalFolderCopyAsync

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);

CreateFileAsync在 InstalledLocation StorageFolder 中拒绝访问?是因为安全原因还是我在这里编码错误?

4

1 回答 1

15

应用程序的安装目录是只读位置。此外,不建议您将数据文件写入安装位置。如果您需要存储仅供应用程序使用的数据,您应该使用

StorageFolder localFolder = ApplicationData.Current.LocalFolder;

或者

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

取决于数据的生命周期。

于 2012-09-03T14:59:56.757 回答