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();
- try
- {
- // 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);
- Console.WriteLine(ctByName.Name);
- // Get Content Type By ID using CSOM Extension Method
- ContentType ctById = ctx.Web.GetContentTypeById(contentTypeId, true);
- Console.WriteLine(ctById.Name);
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine("Error Message: " + ex.Message);
- }
- }
- }
- }

Join the conversation! Your thoughts help the community grow.