在InstalledLocation StorageFolder中尝试CreateFileAsync时拒绝访问?

时间:2012-09-03 14:25:20

标签: c# file-io windows-8 microsoft-metro

我在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:///");

并且"值不在预期范围内"

我可以在CreateFileAsyncWindows.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会拒绝访问? 是因为安全原因还是我在这里写错了什么?

1 个答案:

答案 0 :(得分:15)

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

StorageFolder localFolder = ApplicationData.Current.LocalFolder;

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

取决于数据的生命周期。