How to add the content type to the list using CSOM in SharePoint 2013

By Vijai Anand Jun 28, 2013
In this blog you will see how to add the content type to the list 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 CSOMSamples
{
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 custom list by title
List list = clientContext.Web.Lists.GetByTitle("Custom");

//// Get the content type by id from the web site
ContentType ct = clientContext.Web.ContentTypes.GetById("0x01003D7B5A54BF843D4381F54AB9D229F98A");

//// Add the content type to the custom list
list.ContentTypes.AddExistingContentType(ct);
clientContext.ExecuteQuery();
}
}
}


Vijai Anand

Vijai Anand has been working in IT industry for over 5 years. He holds Bachelor's degree in Electronics and Communication Engineering. Vijai write articles and blogs related to SharePoint 2013, SharePoint 2010, Silv... Read more

COMMENT USING

PREMIUM SPONSORS

Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.

Latest Blogs