I’m trying to write a file from a UWP i’m developing. But i keep getting an acces denied error.
I’ve tried:
Create a console app to write a file using the same filepath and this works.
Resetting windwows rights (done by windows domain admin).
Using different locations. This doesnt help.
I’ve set Visual Studio start as admin. This doesnt help either.
errormessage:
"System.UnauthorizedAccessException: Access to the path
‘C:UsersreindersourcereposUWPTeamAdministrationUWPTeamAdministrationbinx86DebugAppXentrypointplayers.json’
is denied.rn at
System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)rn
at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare
share, FileOptions options)rn at System.IO.File
I really dont know where to go from here. It doesnt seem to me that it is a permissions issue. From what i read i understand by setting VS to start as admin ensures that the app i’m developing also is run in admin mode.
Any ideas?
I’have editted the question because the problem description seems slightly different then in my original post.
2
Answers
Not sure if I need to post this or not. Maybe other new programmers encounter this same problem and can use the info.
It seems to me and correct me if im wrong that reading and writing files from an UWP app are restricted to certain folders. Also the methods used to do this are async methods.
I wasn't aware of the differences between a console app and UWP app at the time I asked.
I found the information on the websites below useful.
https://learn.microsoft.com/en-us/windows/uwp/files/quickstart-reading-and-writing-files
https://www.tutorialspoint.com/windows10_development/windows10_development_file_management.htm#
You should not expect to be able to write to the application folder. Typically apps are installed at locations that do not have write access. If this is a file that you want to reuse then look at some of the other "special" folders that you could use (most likely
ApplicationData
).Note that in any case you should use a sub-folder specific to your app since other apps can read/write to these folders as well.