How to enable DocumentsLibrary capability in a Windows store (WinRT) app?
Asked Answered
T

4

7

I just created a new blank XAML/C# Windows Store app in Visual Studio. I tried to create a file in the Documents folder with this code:

// DEBUG ONLY:
StorageFile file = await KnownFolders.DocumentsLibrary.CreateFileAsync("Hey lol.txt");

But it throws this exception (which I expected):

WinRT information: Access to the specified location (DocumentsLibrary) requires a capability to be declared in the manifest.

Which is fine. I expected it. So I go to Package.appxmanifest and go to Capabilities tab, and to my surprise, there is no "DocumentsLibrary" capability listed.

How do I enable it if it's not even there?

enter image description here

Thenar answered 20/1, 2014 at 3:49 Comment(0)
D
7

Looks like your answer is here. The author shows it available in VS2012, but gone from the list in VS2013, citing MS policy against accessing that particular folder.

[Although] this capability is gone just from the UI, you still can open appxmanifest source and manually add the capability. The result will probably be the same as before – failure of certification for individual developers, so you better stay away from this trick. Microsoft strongly recommend against using Documents Library capability, suggesting Folder and File Pickers instead.

Deuterium answered 20/1, 2014 at 4:12 Comment(5)
A stupid decision on their part. This severely limits the usefulness of many types of apps. Just as I was about to post my solution to this, I saw your answer. My solution was to just add the Capability manually. Thanks @Grant.Thenar
You might not know the answer to this, but if I am selling apps in the Windows Store as a Business (I'm using my Business name), am I allowed to use DocumentsLibrary Capability? I am an "Individual" developer, but it's a business, I'm not trading under my own name, I am trading under my business name - but it's not a Company. In Australia, a Business is not necessarily a Company unless it is registered as a Company and not a Business.Thenar
So what I'm asking is, does Microsoft allow Businesses and Companies to use this capability, or only companies?Thenar
No worries. Looks like I'll need to contact their support people for this. I really don't want to register a Company just yet. It makes no logical sense to do that - because when you register a Company here, you need to do tax and everything even if you don't make money, and you also have to renew the company name ever year (which is around $400).Thenar
Yeah, I agree. I'll still go ahead with development though because most apps I make I end up using for myself anyway, so on the bright side, atleast I can still use DocsLibrary for myself :)Thenar
H
4

As this is UAP the syntax needs to state this, should be as followed

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

You need to add 'uap:' in front of Capability

Husbandman answered 8/11, 2017 at 1:7 Comment(0)
T
3

As per Grant's answer, a way around this is to add the Capability manually.

Right-click the Package.appxmanifest file in Solution Explorer, and select "View code", then either find the Capabilities element, or add it yourself:

...
  <Capabilities>
    <Capability Name="internetClient" />
    <Capability Name="removableStorage" />
    <Capability Name="documentsLibrary" />
  </Capabilities>
</Package>
Thenar answered 20/1, 2014 at 4:20 Comment(3)
and add: FileTypeAssociation : <Extension Category="windows.fileTypeAssociation"> <FileTypeAssociation Name="txt"> <SupportedFileTypes> <FileType>.txt</FileType> </SupportedFileTypes> </FileTypeAssociation>Mucky
@KeMik Where exactly should I add this in the manifest file? It always says app manifest validation failed.Rhizomorphous
@DominikAntal: unfortunately I can't insert code in comment, that's why I shared screenshot with manifest example here: prntscr.com/7ex6k7Mucky
C
3

Here's what you'll get from the Windows Store when you try to publish it

enter image description here

Catania answered 21/11, 2015 at 1:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.