I am trying to overwrite the content of a file but it keeps throwing access denied
System.IO.Stream s2 = await Windows.ApplicationModel.Package.Current.InstalledLocation.OpenStreamForWriteAsync("Assets\\xyz.txt", Windows.Storage.CreationCollisionOption.ReplaceExisting);
System.IO.StreamWriter sw = new StreamWriter(s2);
How can i make it work?? The exception is
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.IO.WindowsRuntimeStorageExtensions.<OpenStreamForWriteAsyncCore>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.IO.WindowsRuntimeStorageExtensions.<OpenStreamForWriteAsyncCore>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at
You can’t write to the area where the package is installed, by the looks of it. From "App packages and deployment":
If you need to update the assets for all users, it sounds like you should just publish a new version, e.g. via the isolated storage API.
If you need to write user-specific data, you’ll need to pick a different location.