How to solve the problem of Permission denied while reading a file from UWP application?

后端 未结 3 406
梦如初夏
梦如初夏 2021-01-27 11:21

I am trying to reading a .txt file of C or D drive in a UWP application. It is ok, when I declare the local variable for file name in assets. But it\'s filed to read file from o

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-27 11:53

    You're getting this exception because UWP is sandboxed and you don't have permission to access that location by default. See here for a full list of locations that you are able to access by default.

    If you absolutely need higher level access to more locations then your only option is to use broadFileSystemAccess (which is also referenced in the above link). This will be a fine option if you're sideloading, but if you're uploading the the app store then you're likely going to run into a tonne of issues.

    Conclusion: It depends entirely on what your needs are but if the file is only going to be read/written by your app then the best option would be to copy it to your apps LocalFolder.

提交回复
热议问题