Access is denied despite using broadFileSystemAccess

别来无恙 提交于 2021-01-22 05:18:45

问题


UWP is killing me.....

I had to reinstall VisualStudio2017 after a computer crash. And now, my app that was working perfectly well before the crash refuses to work.

I've been using the broadFileSystemAccess capability in the Package Manifest, as per the instructions in the MS documentation:

 xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
 IgnorableNamespaces="rescap uap mp desktop4 iot2">

and

<Capabilities>
<rescap:Capability Name="broadFileSystemAccess" />
</Capabilities>

This worked no problem, but now I get an underlined rescap:Capability and the compile warning "The element 'Capabilities' in namespace 'http://schemas.microsoft.com/appx/manifest/foundation/windows10' has invalid child element 'Capability' in namespace .......

Since it's a warning, it compiles without a hickup. However, the application cannot access files (access denied) justa s if this manifest code wasn't there.

I'm holding back saying bad words.... anybody has any idea of what is causing this? It's a fresh VS2017 install.

Thanks!


回答1:


Ok so heres some of my findings.

1. an app must not declare both broadFileSystemAccess and any of the other three file-system capabilities. (Pictures, documents, downloads)

source: https://social.msdn.microsoft.com/Forums/windowsapps/en-US/415d02da-eeb6-45b3-b6e2-946b124d14b0/broadfilesystemaccess-issue?forum=wpdevelop

2. This only works with the storageFile api NOT File.Exists etc api

source: https://docs.microsoft.com/en-gb/windows/uwp/packaging/app-capability-declarations

3. Make sure the fileAccess is enabled as with the other two answers:

source: https://stackoverflow.com/a/57703368/2987066

4. I also found that every time I started debugging (and the code had changed) I needed to turn that setting on and off again to get it to work

source: frustratingly debugging the application through trial and error

Thanks microsoft for your excellent development environment, it really shows how much developers love developing your apps as your store is really flourishing in comparison to your competitors... oh wait..




回答2:


Thank you for reporting this issue. It's a known issue in 1809. The relevant team is working on it.

Clint Rutkas has replied on this thread: No user-consent prompt on first run of broadFileSystemAccess-capable UWP app.

He suggested that we could use try/catch to catch this scenario:

try
{
    StorageFile storageFile = await StorageFile.GetFileFromPathAsync(@"E:\Foo");
}
catch (Exception)
{
    // prompt user for what action they should do then launch below
    // suggestion could be a message prompt
    await Launcher.LaunchUriAsync(new Uri("ms-settings:appsfeatures-app"));
}



回答3:


You also need to allow your app access to the file system in Settings. This a safety measure so the user of the machine acknowledges your app can have access outside the controlled access to files provided by the UWP app container it runs in.



来源:https://stackoverflow.com/questions/53518621/access-is-denied-despite-using-broadfilesystemaccess

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!