TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
PnP Core Component - Set Default Content Type to List in SharePoint 2016
Vijai Anand Ramalingam
Jun 14, 2016
2.7
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
In this blog you will see how to set default content type to list.
Please refer to the
Introduction to PnP Core Component
and
OfficeDevPnP.Core
for more details. I have created a console application and added
SharePointPnPCoreOnline
NuGet package for the SharePoint 2016 version.
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"
;
OfficeDevPnP.Core.AuthenticationManager authMgr =
new
OfficeDevPnP.Core.AuthenticationManager();
try
{
// Get the client context
using
(var ctx = authMgr.GetNetworkCredentialAuthenticatedContext(siteUrl, userName, password, domain))
{
// Set Default Content Type to List using CSOM Extension Method
ctx.Web.SetDefaultContentTypeToList(listTitle, contentTypeId);
}
}
catch
(Exception ex)
{
Console.WriteLine(
"Error Message: "
+ ex.Message);
}
}
}
}
PnP Core Component
SharePoint 2016
Next Recommended Reading
PnP Core Component - Check If Content Type Exists in the List in SharePoint 2016