3
votes

I need to get all documents from Sharepoint site. I start with getting all the document libraries:

private IEnumerable<List> GetAllDocumentLibraries(ClientContext context)
{
    var lists = context.LoadQuery(context.Web.Lists.Where(list => list.BaseType == BaseType.DocumentLibrary));
    context.ExecuteQuery();
    return lists;
}

And then get all the items from each..

var items = list.GetItems(CamlQuery.CreateAllItemsQuery());

_context.Load(items, i => i.Include(it => it.DisplayName, it => it.File));

_context.ExecuteQuery();

Problem is that there is a lot of system libraries that return files such as "controls", "edit-mode-21" and similar. I don't want to filter them out by specific names, since there could be other on another SP sites.

How can I know from the List and its properties if it is user-created list (meaning with documents that I need) or just a sys. library?

Thanks

2

2 Answers

12
votes

There are a couple of conditions you can try. You need to check and select the combination that fits your case:

  • Hidden == false - should exclude most of SharePoint internals (Master Page Gallery, Solution Gallery and others).
  • IsSiteAssetsLibrary == false - this will exclude Site Assets and Site Collection Images. But can also exclude other image libraries created by users.
  • IsCatalog == false - most of catalogs are also hidden, with exception of Style Library.
  • BaseTemplate == 101 - this is template for DocumentLibrary. This will exclude catalogs, image libraries, page libraries and probably some other.
2
votes

You can also exclude system-based lists and document libraries filtering with IsSystemList == false, as well as AllowDeletion == true.