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.

Advertisements
Leave a comment

1 Comment

  1. Kilazur

     /  October 26, 2016

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

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: