0

How to Check if the List is present in SharePoint online site? in CSOM.

1

You can use the PnP Core CSOM library, for SharePoint Online operation. Please find more details here - SharePoint Online List Operations Using PnP Core CSOM Library - Part Two

 // Input Parameters  
    string siteUrl = "https://nakkeerann.sharepoint.com";  
    string userName = "abc@nakkeerann.onmicrosoft.com";  
    string password = "***";  

    // PnP component to set context  
    AuthenticationManager authManager = new AuthenticationManager();  

    try  
    {  
        // Get and set the client context  
        // Connects to SharePoint online site using inputs provided  
        using (var clientContext = authManager.GetSharePointOnlineAuthenticatedContextTenant(siteUrl, userName, password))  
        {  
            // List name input  
            string listName = "TestList";  
            // Checks the list exists  
            bool listExists = clientContext.Site.RootWeb.ListExists(listName);  
            if (listExists)  
            {  
                Console.WriteLine("List is available on the site");  
            }  
            else  
            {  
                Console.WriteLine("List is not available on the site");  
            }  
            Console.ReadKey();  
        }  
    }  
    catch (Exception ex)  
    {  
        Console.WriteLine("Error Message: " + ex.Message);  
        Console.ReadKey();  
    }   
3

Create Client Context of your site then use below code:

ListCollection listCollection = clientContext.Web.Lists;

clientContext.Load(listCollection, lists => lists.Include(list => list.Title).Where(list => list.Title == "Your List Name"));

clientContext.ExecuteQuery();

if (listCollection.Count > 0)
{
    Response.Write("List all ready exist...");
}
else
{
    Response.Write("List not exist");
}

Reference Link: Check List exist or not using CSOM

3
  • what the heck... lists does not have a Where in my CSOM nuget package. – Nicholas DiPiazza May 11 '18 at 20:47
  • Please add LINQ DLL reference for Where – Samir Khimani May 12 '18 at 0:53
  • ok i will try that – Nicholas DiPiazza May 12 '18 at 1:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.