Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access is denied when trying to CreateFileAsync in InstalledLocation StorageFolder?

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"

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

but CreateFileAsync in InstalledLocation StorageFolder gives Access denied ? is that because of security reason or I'm coding something wrong here?

like image 259
isa Avatar asked Sep 03 '12 14:09

isa


1 Answers

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;

or

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

depending on the lifetime of the data.

like image 70
Jeff Brand Avatar answered Nov 23 '22 07:11

Jeff Brand