Programmatically determine List Type in SharePoint Client Object Model

If you would like to programmatically determine a List Type in C# using the SharePoint Client Object Model, then all you need to do is compare the list’s BaseTemplate, which is an integer identifier, to one of the ListTemplateType enumeration values—casting it to an int as seen below:

bool isDocumentLibrary ;
using (ClientContext clientContext = new ClientContext(baseSiteUrl))
{
    Web web = clientContext.Web;
    clientContext.Load(web);
    List list = clientContext.Web.Lists.GetByTitle(listName);
    clientContext.Load(list);
    clientContext.ExecuteQuery();

    if (list.BaseTemplate == (int)ListTemplateType.DocumentLibrary)
    {
        isDocumentLibrary = true;
    }

}

That’s all there is to it.  Now you can take this and modify it in any way that you need to make list type determination more dynamic, if you aren’t just needing to compare to a single ListTemplateType as shown above.

Leave a comment

1 Comment

  1. Kilazur

     /  October 26, 2016

    Wonderful, works better than using List.BaseType, and is more flexible.

    Reply

Leave a comment