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

Grant Winney
  • 65,241
  • 13
  • 115
  • 165
uSeRnAmEhAhAhAhAhA
  • 2,527
  • 6
  • 39
  • 64

4 Answers4

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.

Grant Winney
  • 65,241
  • 13
  • 115
  • 165
  • 1
    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. – uSeRnAmEhAhAhAhAhA Jan 20 '14 at 04:14
  • 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. – uSeRnAmEhAhAhAhAhA Jan 20 '14 at 04:17
  • So what I'm asking is, does Microsoft allow Businesses _and_ Companies to use this capability, or only companies? – uSeRnAmEhAhAhAhAhA Jan 20 '14 at 04:20
  • 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). – uSeRnAmEhAhAhAhAhA Jan 20 '14 at 04:27
  • 1
    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 :) – uSeRnAmEhAhAhAhAhA Jan 20 '14 at 04:29
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

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>
uSeRnAmEhAhAhAhAhA
  • 2,527
  • 6
  • 39
  • 64
3

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

enter image description here

atomaras
  • 2,468
  • 2
  • 19
  • 28