How to Create a Content Type in SharePoint 2013/Office 365 programmatically using CSOM?

In Office 365 environment, you have to provision everything through CSOM. Content type is basic building blocks of any SharePoint List and Libraries.  Here is the CSOM Code snippet to create a new Content type and Its ID.

ContentTypeCollection contentTypes = web.ContentTypes;
cc.Load(contentTypes);
cc.ExecuteQuery();

foreach (var item in contentTypes)
{
if (item.StringId == “0x0101009189AB5D3D2647B580F011XA2F359FB3”)
return;
}

// Create a Content Type Information
ContentTypeCreationInformation newCt = new ContentTypeCreationInformation();

newCt.Name = “Custom Content Employee”;

newCt.Id = “0x0101009189AB5D3D2647B580F011XA2F359FB3″”;

newCt.Group = “Custom Content Employee Groups”;
// Create the content type
ContentType myContentType = contentTypes.Add(newCt);
cc.ExecuteQuery();

Please read my another blog to know more about delete ContentTypes in Sharepoint 2013/Office 365 using CSOM

Happy SharePointing Folks !! Hope it helps you.

Leave a Reply

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