Querying Vaults

Vaults can be queried using the Query method.


You can filter vaults by id

//vault 13
var vault13 = client.Query<Vault>().Where(v => v.Id == 13).FirstOrDefault();

or by the current users access rights. The VaultRoles value that is used will include all vaults where the user has this access.

//vaults with contribute access or more
var vaults = client.Query<Vault>().Where(v => v.CurrentUserRole == VaultRoles.Contribute).ToList();

The filter will return all vaults where the user has at least the requested access level. So if we filter all vaults with access level View, we will also get vaults where we have Contribute and Full Access levels.


Normally the AccessList and Metadata properties are not populated by default. To include them in the query we need to add them using the Include statement.

var allVaults = client.Query<Vault>()
    .Include(v => v.AccessList)
    .Include(v => v.MetadataDefinitions).ToList();

Order by

Vault queries don't support server side sorting, so Order by and Skip/Take combos are not supported. You need to execute the query first (for example by invoking ToList()) and then apply sort/skip/take combos.

//this will throw an InvalidQueryException 
try {
    var orderedVaults = client.Query<Vault>().OrderBy(v => v.Name).Skip(10).ToList();
} catch (InvalidQueryException e) {
//this will work
var orderedVaults2 = client.Query<Vault>().ToList().OrderBy(v => v.Name).Skip(10).ToList();

Vault statistics

To get more information about the media stored in the vault, you can load the VaultStatistics of a vault.

Here you can access the number of media stored in the vault and how many of these that are published.

//get statistics for vault 13
var vaultStatistics = client.Load<VaultStatistics>(13).Single();
Console.WriteLine(@"Vault {0} contains {1} number of items and of these are {2} items published.", 
    vaultStatistics.Id, vaultStatistics.NoOfItems, vaultStatistics.NoOfPublishedItems);
comments powered by Disqus
+46 (0)480 - 31 47 95
English website