.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Articles >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Articles

PnP Core Component - Add Content Type to List by name in SharePoint 2016

Posted By:Vijai Anand. R       Posted Date: May 20, 2016    Points: 25    Category: SharePoint    URL: http://www.dotnetspark.com  

In this article you will see how to add content type to list by name in SharePoint 2016.

Please refer Introduction to PnP Core Component for more details. I have created a console application and added SharePointPnPCoreOnline NuGet package for SharePoint 2016 version. 


Adds content type to list. 

web: Site to be processed - can be root web or sub site 

listTitle: Title of the list 

contentTypeName: Name of the content type 

defaultContent: Optionally make this the default content type 

searchContentTypeInSiteHierarchy: search for content type in site hierarchy 

Code Snippet:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using OfficeDevPnP.Core;

namespace SP2016PnPCoreComponentDemo
    class Program
        static void Main(string[] args)
            // Input Parameters
            string siteUrl = "http://c7395723754:35298/sites/VijaiDemo";
            string userName = "administrator";
            string password = "xxxxxxx";
            string domain = "AD2012";
            string listTitle = "PnP Custom List";
            string contentTypeName = "PnP Content Type";

            OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();

                // Get the client context
                using (var ctx = authMgr.GetNetworkCredentialAuthenticatedContext(siteUrl, userName, password, domain))
                    // Add Content Type to list by name using CSOM Extension Method  
                    ctx.Web.AddContentTypeToListByName(listTitle, contentTypeName, true, false);

            catch (Exception ex)
                Console.WriteLine("Error Message: " + ex.Message);

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend