0

Firstly, before anyone marks this question as a duplicate, read this. I read through many questions that are potential duplicates of this one, like this, yet none of the solutions that seemed applicable in my situation worked for me.

So, I have some code below to save text to a file (note: all variables have already been defined):

await Task.Run(() => File.WriteAllText(documentFile.Path, documentToSave));

But then, the a System.UnauthorisedAccessException is thrown at that line.

How can I fix this? Any solutions would be appreciated! Thanks in advance!

Community
  • 1
  • 1
Theo
  • 548
  • 2
  • 8
  • 19
  • Check that the documentFile.Path is a valid path, and that no other threads are using it – Aydin Feb 20 '16 at 05:45
  • What is your documentFile.Path? You know the App Container contains your writing privilege within the app folder. – Jackie Feb 22 '16 at 07:54

1 Answers1

0

Per the "win-universal-app" tag, assuming you are writing a universal windows app, please make sure you have read File access permissions and your app have write right to the file path.

Haibara Ai
  • 10,703
  • 2
  • 31
  • 47