UWP Accessing Documents Library

November 11, 2016

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.

Profile picture

A blog about one man's journey through code… and some pictures of the Peak District

© Paul Michaels 2024