user14492
user14492

Reputation: 2234

How to save files to Documents folder on Hololens?

I want to save some persistent JSON files on Hololens. They need to persist across builds of application so Application.persistentDataPath doesn't work. I chose to Documents because it makes the most sense. There is no Downloads folder on Hololens.

Here's what I've tried so far:

I have read the App Capability Documentation and manually added the <uap:Capability Name="documentsLibrary"/> to the Package.appxmanifest to the file.

I also added the xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" namespace. But I get the following 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: 'DeviceCapability' in namespace 'http://schemas.microsoft.com/appx/manifest/foundation/windows10'. Ad-Hoc Localz D:\Repositories\ad-hoc-localization\_build\Ad-Hoc Localz\Package.appxmanifest 37 

and the following error on build:

Error APPX0501 Validation error. error C00CE014: App manifest validation error: The app manifest must be valid as per schema: Line 45, Column 6, Reason: Element '{http://schemas.microsoft.com/appx/manifest/uap/windows10}Capability' is unexpected according to content model of parent element '{http://schemas.microsoft.com/appx/manifest/foundation/windows10}Capabilities'. Expecting: {http://schemas.microsoft.com/appx/manifest/foundation/windows10}DeviceCapability. Ad-Hoc Localz D:\Repositories\ad-hoc-localization_build\build\bin\Win32\Master\AppxManifest.xml 1 

It also says that I need to specify file type I used this documentation to add that manually to manifest. But I get the same warning i.e. invalid child element. I do not see a GUI based way to add like in this image from this forum

So how do I build an application that has access to Documents folder on Hololens?

In the code I'm using Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) to get path to documents but in code snippet they show that it should be KnownFolders.DocumentsLibrary. Is the Environment not valid namespace on UWP?

Link to the whole manifest.

Upvotes: 1

Views: 1817

Answers (1)

Gaurav sharma
Gaurav sharma

Reputation: 41

  1. Don't use

xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" because DocumentLibrary capability is in uap namespace. add document capability like below

<Capabilities>  
    <Capability Name="internetClientServer"/>
   <Capability Name="internetClient"/>
   <uap:Capability Name="documentsLibrary"/>
  <DeviceCapability Name="microphone"/>  
</Capabilities>

now you should not get warning.

  1. Use below lines of code to create and get file in Document folder

     IReadOnlyList<Windows.Storage.StorageFile> 
     file=awaitKnownFolders.DocumentsLibrary.CreateFileAsync("FileName");
    
     IReadOnlyList<Windows.Storage.StorageFile> 
     file=awaitKnownFolders.DocumentsLibrary.GetFileAsync("filename")
    

Upvotes: 2

Related Questions