How to get content type by id using CSOM in SharePoint 2013


Namespaces:

using Microsoft.SharePoint.Client;
Assemblies:
Microsoft.SharePoint.Client.dll;
Microsoft.SharePoint.Client.RunTime.dll;

Code Snippet:

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using Microsoft.SharePoint.Client;

 

namespace GetContentType

{

    class Program

    {

        static void Main(string[] args)

        {

            //// String Variable to store the siteURL

            string siteURL = "http://c4968397007/";

 

            //// Get the context for the SharePoint Site to access the data

            ClientContext clientContext = new ClientContext(siteURL);

 

            //// Get the content type using ID: 0x0120D520 - is the ID of the Document Set content Type

            ContentType ct = clientContext.Web.ContentTypes.GetById("0x0120D520");

            clientContext.Load(ct);

            clientContext.ExecuteQuery();

 

            //// Display the content type name - Output will be "Document Set"

            Console.WriteLine(ct.Name);

            Console.ReadLine();

        }

    }

}