3

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

Filip
  • 1,824
  • 4
  • 18
  • 37

2 Answers2

12

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.
dstarkowski
  • 337
  • 3
  • 14
  • Thanks, these 3 properties helped to eliminate nearly all "extra" files, I now have to deal just with some .aspx one. About BaseTemplate, wouldn't this exclude also user created doc. library that uses the default template? – Filip Jun 09 '16 at 11:55
  • BaseTemplate also can be 700 if you are using OneDrive/personal site. – Chuck Norris May 11 '21 at 15:24
2

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

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197