PnP Core Component - Check If Web Site Exists 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 SharePointPnPCoreOnline 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.   
  9. namespace SP2016PnPCoreComponentDemo  
  10. {  
  11.     class Program  
  12.     {  
  13.         static void Main(string[] args)  
  14.         {  
  15.             // Input Parameters  
  16.             string siteUrl = "http://c7395723754/";  
  17.             string userName = "administrator";  
  18.             string password = "Vk3p8L16E6";  
  19.             string domain = "AD2012";            
  20.             string leafURL = "pnpdemosite";  
  21.             string webFullURL = "http://c7395723754/pnpdemosite";  
  22.   
  23.             OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();  
  24.   
  25.             try  
  26.             {  
  27.                 // Get the client context  
  28.                 using (var ctx = authMgr.GetNetworkCredentialAuthenticatedContext(siteUrl, userName, password, domain))  
  29.                 {  
  30.                     // Check if a child web site exists with the specified leaf URL  
  31.                     if (ctx.Web.WebExists(leafURL))  
  32.                     {  
  33.                         Console.WriteLine(leafURL + " - site exists");  
  34.                     }  
  35.   
  36.                     // Check if a web site exists at the specified full URL  
  37.                     if (ctx.WebExistsFullUrl(webFullURL))  
  38.                     {  
  39.                         Console.WriteLine(webFullURL + " - site exists");  
  40.                     }                      
  41.                 }  
  42.             }  
  43.   
  44.             catch (Exception ex)  
  45.             {  
  46.                 Console.WriteLine("Error Message: " + ex.Message);  
  47.             }  
  48.         }  
  49.     }  
  50. }
Ebook Download
View all
Learn
View all