PnP Core Component - Check If List Exists in SharePoint 2016

Please refer to Introduction to PnP Core Component 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.Net;  
  5. using System.Text;  
  6. using System.Threading.Tasks;  
  7. using Microsoft.SharePoint.Client;  
  8. using OfficeDevPnP.Core;  
  9.   
  10. namespace SP2016PnPCoreComponentDemo  
  11. {  
  12.     class Program  
  13.     {  
  14.         static void Main(string[] args)  
  15.         {  
  16.             // Input Parameters  
  17.             string siteUrl = "http://c7395723754:35298/sites/VijaiDemo";  
  18.             string userName = "administrator";  
  19.             string password = "Xxxxxxxxx";  
  20.             string domain = "AD2012";  
  21.             string listName = "PnP Custom List";  
  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 list exists using CSOM Extension Method  
  31.                     if (ctx.Web.ListExists(listName))  
  32.                     {  
  33.                         Console.WriteLine(listName + " exists");  
  34.                     }  
  35.                     else  
  36.                     {  
  37.                         Console.WriteLine(listName + " does not exists.");  
  38.                     }  
  39.                 }  
  40.             }  
  41.   
  42.             catch (Exception ex)  
  43.             {  
  44.                 Console.WriteLine("Error Message: " + ex.Message);  
  45.             }  
  46.         }  
  47.     }  
  48. }
Ebook Download
View all
Learn
View all