.NET life

HUGON Jérôme
Microsoft Certified Technology Specialist Microsoft Certified Application Developer Microsoft Certified Professional

Add a content type on a list in C#

SharePoint 2007

Category SharePoint 2007  | Publication Date : 7/6/2009

Code sample for adding a content type on a list:

private static void AddContentType(SPWeb web, string listName,string contentTypeName)
{
    SPList list = web.Lists[listName];
    SPContentType newContentType = web.Site.RootWeb.ContentTypes[contentTypeName];
    list.ContentTypes.Add(newContentType);
    list.Update();
}