PnP Core Component - Set Home Page In SharePoint 2016

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
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. using Microsoft.SharePoint.Client;  
  7. using OfficeDevPnP.Core;  
  8. using OfficeDevPnP.Core.Extensions;  
  9. using Microsoft.SharePoint.Client.Taxonomy;  
  10.   
  11. namespace SP2016PnPCoreComponentDemo  
  12. {  
  13.     class Program  
  14.     {  
  15.         static void Main(string[] args)  
  16.         {  
  17.             // Input Parameters    
  18.             string siteUrl = "http://c7395723754/";  
  19.             string userName = "administrator";  
  20.             string password = "xxxxxxxxx";  
  21.             string domain = "AD2012";  
  22.             string rootFolderRelativeURL = "SitePages/NewHome.aspx";  
  23.   
  24.             OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();  
  25.   
  26.             try  
  27.             {  
  28.                 // Get the client context    
  29.                 using (var ctx = authMgr.GetNetworkCredentialAuthenticatedContext(siteUrl, userName, password, domain))  
  30.                 {  
  31.                     // Set Home Page  
  32.                     ctx.Web.SetHomePage(rootFolderRelativeURL);  
  33.                 }  
  34.             }  
  35.   
  36.             catch (Exception ex)  
  37.             {  
  38.                 Console.WriteLine("Error Message: " + ex.Message);  
  39.             }  
  40.         }  
  41.     }  
  42. }  
Ebook Download
View all
Learn
View all