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

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
arneyjfs
  • 180
  • 1
  • 2
  • 10
  • the answer still has not changed – Ken Tucker Dec 03 '17 at 19:51
  • Thanks for your response. So how do other apps do it? – arneyjfs Dec 03 '17 at 23:05
  • Can you tell me location which you want access, my sample link in this question https://stackoverflow.com/questions/47453463/uwp-xaml-imagebrush-imagesource-from-networkshare/47454666#47454666 might use full for you. Also share location want to access and file type with some codes so i can help you – Shubham Sahu Dec 04 '17 at 04:51
  • 1
    Please refer to my answer https://stackoverflow.com/questions/47344292/how-to-get-all-sub-folders-and-its-files-uwp/47344969#47344969 . Unlike Win32 Apps, UWP apps need user's permission to access a folder directly. – Pratyay Dec 04 '17 at 05:28
  • 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. – Sean O'Neil Dec 04 '17 at 09:14
  • 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? – arneyjfs Dec 04 '17 at 21:02
  • Possible duplicate of [Windows 10 Universal App File/Directory Access](https://stackoverflow.com/questions/33082835/windows-10-universal-app-file-directory-access) – Geoff James Dec 04 '17 at 21:30

3 Answers3

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.

arneyjfs
  • 180
  • 1
  • 2
  • 10
  • 2
    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. – Paul McCarthy Jul 22 '19 at 09:35
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.

Barry Wang
  • 1,459
  • 1
  • 8
  • 12
  • 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 answer – arneyjfs Dec 06 '17 at 11:06
0

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