Reputation: 81
I am trying to store a file to the app's storage in a Windows Phone 8.1 app, but it always fails with a System.UnauthorizedAccessException.
The exception occurs on the following line (no related code before that):
StorageFile storageFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("test.xml", CreationCollisionOption.ReplaceExisting);
Upvotes: 3
Views: 2287
Reputation: 81
Finally found the issue:
I had a call to
Windows.Storage.ApplicationData.Current.LocalFolder.DeleteAsync()
in code that ran once after installing the app. Therefore all writing to this folder failed after that point.
I am not sure why GenerateUniqueName
made the UnauthorizedAccessException disappear before, but since I wasn't able to read the file when using GenerateUniqueName
I assume that specific code path doesn't ever throw that exception for some reason, maybe because it assumes there can never be an issue when using unique file names.
Upvotes: 4