Adding content type programatically

Scenario:
You want to add Content Type programatically

Solution:
SharePoint Object Model

Code:
  1. using (SPSite site = new SPSite("http://localhost")) {   
  2.   
  3. using (SPWeb web = site.OpenWeb()) {   
  4.   
  5. SPContentType baseType = web.AvailableContentTypes["Document"];  
  6.   
  7.  SPContentType proposal = new SPContentType( baseType, web.ContentTypes, "Project Proposal");   
  8.   
  9. proposal.FieldLinks.Add(new SPFieldLink(web.AvailableFields["Author"]));   
  10.   
  11. web.ContentTypes.Add(proposal);   
  12.   
  13. }  
  14. }  

Comments

Popular posts from this blog

SharePoint 2016 and 2019 Ports

PsConfig step by step /Configuration Wizard. “Upgrade Available” vs “Upgrade required”

Unlock the SharePoint site using Powershell command