How to create ContentTypes in Sharepoint 2013/Office 365 using CSOM

In this article, we will learn about ContentType creation in Sharepoint 2013/Office 365 using CSOM.  Below is the sample CSOM code to achieve the same.

ClientContext cc = new ClientContext(siteUrl);
cc.AuthenticationMode = ClientAuthenticationMode.Default;
cc.Credentials = new SharePointOnlineCredentials(userName, pwd);
Web web = cc.Web;

ContentTypeCollection contentTypes = web.ContentTypes;

foreach (var item in contentTypes)
if (item.StringId == “0x0101009189AB5D3D2647B580DFGT56F356FB2”)

// Create a Content Type

ContentTypeCreationInformation newCt = new ContentTypeCreationInformation();
// Set the name for the content type
newCt.Name = “custom content type”;
newCt.Id = “0x0101009189AB5D3D2647B580DFGT56F356FB2”;
// Set content type

newCt.Group = “Custom content type”;

// Create the content type
ContentType myContentType = contentTypes.Add(newCt);

Hope it helps!! Happy Sharepointing :-)

Leave a Reply

Your email address will not be published. Required fields are marked *