Please refer to the Introduction to PnP Core Component and OfficeDevPnP.Core for more details. I have created a Console Application and added SharePointPnPCore2016 NuGet package for the SharePoint 2016 version.
Code Snippet
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.SharePoint.Client;
- using OfficeDevPnP.Core;
- using OfficeDevPnP.Core.Extensions;
- using Microsoft.SharePoint.Client.Taxonomy;
- namespace SP2016PnPCoreComponentDemo
- {
- class Program
- {
- static void Main(string[] args)
- {
- // Input Parameters
- string siteUrl = "http://c7395723754/";
- string userName = "administrator";
- string password = "xxxxxxxx";
- string domain = "AD2012";
- Guid featureID = new Guid("961d6a9c-4388-4cf2-9733-38ee8c89afd4");
- OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();
- try
- {
- // Get the client context
- using (var ctx = authMgr.GetNetworkCredentialAuthenticatedContext(siteUrl, userName, password, domain))
- {
- // Check if faeture is activated in web
- if (ctx.Web.IsFeatureActive(featureID))
- {
- // Deactivate the feature in web
- ctx.Web.DeactivateFeature(featureID);
- }
- else
- {
- // Activate the feature in web
- ctx.Web.ActivateFeature(featureID);
- }
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine("Error Message: " + ex.Message);
- }
- }
- }
- }

kalu singh raoPosted Jul 27, 2016, 1:48 AM
Nice sir