Search code examples
c#.netxamarin.formsuwpclass-library

Access files and folders of Internal Computer drives in CrossPlatform UWP


Making a class library that works for all system and it resolves around storage (system.io). So far it works for Winforms and Wpf but its failing to work on UWP. I also have a total of 3 internal storage drives

C:/
D:/
E:/

I can get files and folders from the C drive but not from D or E. I've added this into the .UWP Package.appxmanifest

xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap mp rescap">`
    <Capabilities>
        <rescap:Capability Name="broadFileSystemAccess"/>
        <uap:Capability Name="musicLibrary"/>
        <uap:Capability Name="removableStorage"/>
        <uap:Capability Name="picturesLibrary"/>
        <uap:Capability Name="videosLibrary"/>
        <uap:Capability Name="documentsLibrary"/>
      </Capabilities>`

But the <rescap:Capability Name="broadFileSystemAccess"/> is giving me a warning

Severity Code Description Project File Line Suppression State Warning The element 'Capabilities' in namespace 'http://schemas.microsoft.com/appx/manifest/foundation/windows10' has invalid child element 'Capability' in namespace 'http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities'. List of possible elements expected: 'CapabilityChoice' in namespace 'http://schemas.microsoft.com/appx/manifest/foundation/windows10' as well as 'Capability' in namespace 'http://schemas.microsoft.com/appx/manifest/uap/windows10' as well as 'Capability' in namespace 'http://schemas.microsoft.com/appx/manifest/foundation/windows10' as well as 'Capability' in namespace 'http://schemas.microsoft.com/appx/manifest/uap/windows10/4' as well as 'Capability' in namespace 'http://schemas.microsoft.com/appx/manifest/uap/windows10/6' as well as 'Capability' in namespace 'http://schemas.microsoft.com/appx/manifest/uap/windows10/7' as well as 'Capability' in namespace 'http://schemas.microsoft.com/appx/manifest/uap/windows10/3' as well as 'Capability' in namespace 'http://schemas.microsoft.com/appx/manifest/uap/windows10/2' as well as 'CustomCapabilityChoice' in namespace 'http://schemas.microsoft.com/appx/manifest/foundation/windows10' as well as 'CustomCapability' in namespace 'http://schemas.microsoft.com/appx/manifest/uap/windows10/4' as well as 'Dev....

And I take this to mean that the broadFileSystemAccess isn't working. The UWP app has shown in system settings for file system and I've allowed it but still same failure.

An example of a filepath used are

@"D:\Games\Genshin Impact/7z.dll"
@"D:\Games\Genshin Impact\7z.dll"
"D:\\Games\\Genshin Impact\\7z.dll"

Used these 2 file libraries

System.IO

File & Folder

Windows.Storage

StorageFile & StorageFolder

I've attempted to use a File/Folder picker and it occasional worked, but I want to try and avoid using them because this is meant to be a .DLL that can be used like System.IO.File/Folder and other librarys.

Any help would be very much appreciated.

Edit: Figured it out, I had to remove the other storage related capabilities.

<uap:Capability Name="musicLibrary"/>
<uap:Capability Name="removableStorage"/>
<uap:Capability Name="picturesLibrary"/>
<uap:Capability Name="videosLibrary"/>
<uap:Capability Name="documentsLibrary"/>

After that I built, stopped it, unchecked and rechecked the file permissions in system settings than built and it worked.


Solution

  • Figured it out, I had to remove the other storage related capabilities.

    <uap:Capability Name="musicLibrary"/>
    <uap:Capability Name="removableStorage"/>
    <uap:Capability Name="picturesLibrary"/>
    <uap:Capability Name="videosLibrary"/>
    <uap:Capability Name="documentsLibrary"/>
    

    After that I built, stopped it, unchecked and rechecked the file permissions in system settings than built and it worked.