I am writing a Windows Phone 8.1 (WINRT XAML) app.
In method 1, I am opening a StorageFile, and in method 2 I am writing on the same file. But it shows error while writing to the file.
- How to close this file after opening and reading contents?
Then how to close this file again after writing to it in method 2?
private async Task<bool> Method1(int workOutID) { string filename = "WorkoutOfflineDataFile.txt"; StorageFolder LocalStorageFolderObject = ApplicationData.Current.LocalFolder; StorageFile StorageFileObject = await LocalStorageFolderObject.CreateFileAsync(filename, CreationCollisionOption.OpenIfExists); string JSONFromFile = await FileIO.ReadTextAsync(StorageFileObject); } private async void Method2() { string filename = "WorkoutOfflineDataFile.txt"; StorageFolder LocalStorageFolderObject = ApplicationData.Current.LocalFolder; StorageFile StorageFileObject = await LocalStorageFolderObject.CreateFileAsync(filename, CreationCollisionOption.OpenIfExists); await FileIO.WriteTextAsync(StorageFileObject, JSonData_ToSave); }
ERROR:
Exception thrown: 'System.UnauthorizedAccessException' in mscorlib.ni.dll
Additional information: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))