PnP, which stands for Practices and Patterns, is a community driven open source project where Microsoft and community members have created an implementation pattern for Office 365 and SharePoint on-premises. One of the branches of the PnP development is in PnP Core CSOM Library.
PnP Core library provides CSOM extension methods for SharePoint 2016 add-in model development. The official documentation can be accessed from here. PnP Core library increases the productivity of developers by abstracting complex operations. In this article, we will see how to set up PnP Core Library remotely and work with SharePoint 2016 using a Console application.
In order to work with PnP Core Library, we first have to install the NuGet Package Manager which is explained in this article. Once the PnP Core Library is added, we can kick off the implementation using a Console application.
Project structure
Create a console application and add the below references.
- Microsoft.SharePoint.Client;
- OfficeDevPnP.Core;
Scope of the article will be to perform the below operations using PnP Core CSOM Library.
- Activate the site collection feature : SharePoint Server Publishing Infrastructure
- Deactivate the feature using PnP Core Library.
Activate the Feature
Let’s see how to activate the feature using the PnP extension method.
- Create instance of the Authentication Manager which will be used to create the Client Context.
- //Get instance of Authentication Manager
- OfficeDevPnP.Core.AuthenticationManager authenticationManager = new OfficeDevPnP.Core.AuthenticationManager();
- //Create authentication array for site url,User Name,Password and Domain
- string[] authArray = { "http://sharepoint2016/sites/HOL", "Priyaranjan","password-1","SharePointHOL" };
- Create Client Context by passing the authentication details to the Authentication Manager object,
- var clientContext = authenticationManager.GetNetworkCredentialAuthenticatedContext(authArray[0], authArray[1],authArray[2], authArray[3])
- Get the GUID of the feature and deactivate the feature using the PnP extension method ‘ActivateFeature’.
- Guid featureID = new Guid("f6924d36-2fa8-4f0b-b16d-06b7250180fa");
- //Activate the site collection feature using extension method
- clientContext.Site.ActivateFeature(featureID);


Full Code
The full code to activate the site feature, using PnP Extension method is, as shown below:
- //Get instance of Authentication Manager
- OfficeDevPnP.Core.AuthenticationManager authenticationManager = new OfficeDevPnP.Core.AuthenticationManager();
- //Create authentication array for site url,User Name,Password and Domain
- string[] authArray = {
- "http://sharepoint2016/sites/HOL",
- "Priyaranjan",
- "password-1",
- "SharePointHOL"
- };
- try {
- //Create the client context
- using(var clientContext = authenticationManager.GetNetworkCredentialAuthenticatedContext(authArray[0], authArray[1], authArray[2], authArray[3])) {
- Guid featureID = new Guid("f6924d36-2fa8-4f0b-b16d-06b7250180fa");
- //Activate the site collection feature using extension method
- clientContext.Site.ActivateFeature(featureID);
- Console.WriteLine("SharePoint Server Publishing Infrastructure feature has been Activated.");
- Console.ReadLine();
- }
- } catch (Exception ex) {
- Console.WriteLine("Exception : " + ex.Message);
- }



Tarun DPosted Sep 6, 2016, 4:21 AM
Thanks for sharing..
Prasanna MuraliPosted Sep 5, 2016, 10:57 AM
Nice post
Vignesh ManiPosted Sep 4, 2016, 5:03 PM
Good one