UWP Accessing Documents Library

Accessing the documents library from a UWP app is frowned upon by Microsoft; however, it is possible. Here is some code that will access the library:

var files = await KnownFolders.DocumentsLibrary.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.OrderByName);
foreach (var f in files)
    BasicProperties props = await f.GetBasicPropertiesAsync();

This will access the library and get the properties for each file. However, just running it will fail with this error:


So, you’ll probably get this error and, like me (and not for the first time), go looking for it here:


Of course, you won’t find it (because it’s not there), and then you’ll turn to Google. If that brought you here then you’re next step is to open the manifest file directly:

    <uap:Capability Name="documentsLibrary" />

If there are already Capabilities then just add the line:

    <uap:Capability Name="documentsLibrary" />

Note: you need the uap prefix.

And, that’s not all. Next you need to tell it which documents it can access:

        <uap:Extension Category="windows.fileTypeAssociation">
          <uap:FileTypeAssociation Name=".txt">
    <uap:Capability Name="documentsLibrary" />

And that’s it. I can understand why they have all these restrictions, but they can be frustrating for programmers.

1 thought on “UWP Accessing Documents Library

  1. Mickaël

    Ok but even after that when we arrive for publishing our app in the store, they ask for un society number to be able tu use this capability !! Grrrrrr !!!!

This site uses Akismet to reduce spam. Learn how your comment data is processed.