UWP access denied
Asked Answered
A

3

8

Basically, I am having huge difficulty getting a text file to open by my UWP app. I have set the app permissions to be able to access files in 'my documents' and other options of known libraries like 'my pictures' but any attempt to open a file not located in these places is met by an 'Access Denied' error. From trawling the internet I know this is a known issue and has been asked a few times, but all threads seem to lead to the conclusion that you simply cannot access these files without getting the user to access it via the file picker (due to sandboxing). See thread below for example:

https://social.msdn.microsoft.com/Forums/en-US/2ab6e209-cad7-4254-a252-b8e752ea7d13/uwp-how-can-i-access-locally-stored-files-not-on-removable-storage?forum=WindowsIoT

I know asking the same question again and hoping for a different response sounds futile but I know for a fact that this cannot be the whole answer. I know this because I have downloaded other notepad apps from the store (e.g. modern notepad) and they allow this behaviour with no issues. How are they doing this???

This has been driving me mad for months and I really hope someone can help

Agan answered 3/12, 2017 at 18:26 Comment(7)
the answer still has not changedNial
Thanks for your response. So how do other apps do it?Agan
Can you tell me location which you want access, my sample link in this question #47453963 might use full for you. Also share location want to access and file type with some codes so i can help youRapturous
Please refer to my answer #47344792 . Unlike Win32 Apps, UWP apps need user's permission to access a folder directly.Alephnull
Pratyay's answer is correct. Short version, you can access any folder and its contents but the user must have explicitly opened it with a picker first. When that is done the token can be stored in the FutureAccessList.Fantastically
Thank you guys. I REALLY appreciate your help. I think I understand how I'd go about getting the user to access the file with the file picker and storing that for later use... It really is more how these other apps are doing it that mystifies me. So far what you have said seems to be backed up by everything else I have read, so by all rights, apps like 'Modern Notepad' SHOULD NOT be able to do what they are doing. They must have found a way around?Agan
Possible duplicate of Windows 10 Universal App File/Directory AccessEconah
A
5

5 months later...

It appears Microsoft have now added the capability. Simply add the 'broadFileSystemAccess' capability to the app manifest as described here: https://learn.microsoft.com/en-us/windows/uwp/files/file-access-permissions

Note that this still requires user input to some extent (the user must grant permission to file system access on first run of the app) but that the file/folder picker UI is not needed.

I haven't actually tried this yet but it sounds like it should do the job. I hope it helps people referring to this post in the future.

Agan answered 19/5, 2018 at 9:15 Comment(1)
I've tried it and it does not work! Also I have gone into "Choose which apps can access your file system" and set my app to Yes and it still does not work. What does this setting do? No wonder the Microsoft app store is such a failure.Fit
B
1

First, you need to put broadFileSystemAccess in your Package.XML

https://learn.microsoft.com/en-us/windows/uwp/files/file-access-permissions

<Package
  ...
  xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
  IgnorableNamespaces="uap mp rescap">
...
<Capabilities>
    <rescap:Capability Name="broadFileSystemAccess" />
</Capabilities>

Then your app will shows up with an access setting under Privacy > File system. The setting is not enabled by default and must be enabled during development.

enter image description here

Brazenfaced answered 26/4, 2021 at 14:21 Comment(0)
C
0

Yep like you've already known, a common UWP app cannot directly access some paths that is not allowed. You need a broker to help you access it using FilePicker. I believe you can found lots of articles about this.

So why you can see some notepads in the store which seems different? This is because those apps are converted apps which used DesktopBridge technology. Desktopbridge allows common desktop apps to works in UWP app container and have more privilege. Although it has some problems for path that you need to notice, like the following blogs mentioned: blog1 and blog2.

Carpathoukraine answered 5/12, 2017 at 8:22 Comment(1)
Thank you so much. This is the reason I was looking for. That seems very strange and really frustrating for me but I guess there's no way around it. Thank you for your answerAgan

© 2022 - 2024 — McMap. All rights reserved.