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

Top 5 Contributors of the Month
Sandeep Singh

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

 Subscribe to Articles

PnP Core Component - Get Content Type from Web in SharePoint 2016

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

In this article you will see how to get content type from web in SharePoint 2016.

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

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 contentTypeId = "0x0100FC6F80F7923849FBBF73F0974A2DEB9E";
            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))
                    // Get Content Type By Name using CSOM Extension Method                     
                    ContentType ctByName = ctx.Web.GetContentTypeByName(contentTypeName, true);

                    // Get Content Type By ID using CSOM Extension Method                     
                    ContentType ctById = ctx.Web.GetContentTypeById(contentTypeId, true);

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


 Subscribe to Articles


Further Readings:

Author: Kaviyaa         Company URL: www.softwaretestingchennai.in
Posted Date: July 18, 2016

That is very interesting; you are a very skilled blogger. I have shared your website in my social networks!

<a href="http://www.softwaretestingchennai.in/courses/selenium-training-in-chennai/">Selenium Training in Chennai</a>

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