在InstalledLocation StorageFolder试图CreateFileAsync时,访问被拒绝? [英] Access is denied when trying to CreateFileAsync in InstalledLocation StorageFolder?
问题描述
我在InstalledLocation StorageFolder试图CreateFileAsync时,访问被拒绝
I got Access is denied when trying to CreateFileAsync in InstalledLocation StorageFolder
StorageFolder storageFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFile file = await storageFolder.CreateFileAsync("fileNmae", Windows.Storage.CreationCollisionOption.ReplaceExisting);
我也试过
Also I tried
var storageFolder = await StorageFolder.GetFolderFromPathAsync("ms-appx:///");
和获得值不会落在预期范围内
And got "value does not fall within the expected range"
我可以去周围和 CreateFileAsync
Windows.Storage.ApplicationData.Current.LocalFolder
然后 CopyAsync
来InstalledLocation StorageFolder?
I can go around and CreateFileAsync
in Windows.Storage.ApplicationData.Current.LocalFolder
then CopyAsync
to 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);
但 CreateFileAsync
在InstalledLocation StorageFolder给出拒绝访问?
是由于安全的原因还是我编码什么错在这里?
but CreateFileAsync
in InstalledLocation StorageFolder gives Access denied ?
is that because of security reason or I'm coding something wrong here?
推荐答案
应用程序的安装目录是只读位置。此外,它不会被建议写入数据文件到安装位置。如果你需要存储的数据,这是因为只有应用程序的使用,你应该使用
The app's install directory is a read-only location. In addition, it would not be recommended that you write data files to the installed location. If you need to store data this is for the application's use only, you should use
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
或
Windows.Storage.StorageFolder temporaryFolder = ApplicationData.Current.TemporaryFolder;
根据数据的寿命。
depending on the lifetime of the data.
这篇关于在InstalledLocation StorageFolder试图CreateFileAsync时,访问被拒绝?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!