Retrieve All Lists and Libraries from SharePoint Web using CSOM

  1. //using Microsoft.SharePoint.Client;  
  2. //using System.Net  
  3. //GetAllLists(credentials, weburl);  
  4.   
  5. //This method returns all the lists and libraries from SharePoint website  
  6. private static void GetAllLists(ICredentials credentials, string weburl)  
  7. {  
  8.     using (ClientContext ctx = new ClientContext(weburl))  
  9.     {  
  10.         ctx.Credentials = credentials;  
  11.         Web oweb = ctx.Web;  
  12.         ListCollection lists = oweb.Lists;  
  13.         ctx.Load(lists);  
  14.         ctx.ExecuteQuery();  
  15.         Console.WriteLine("All Lists / Libraries: " + lists.Count().ToString());  
  16.         foreach (List lst in lists)  
  17.         {  
  18.             Console.WriteLine(lst.Title);  
  19.         }  
  20.     }  
  21.     Console.WriteLine("Press any key to exit...");  
  22.     Console.Read();  
  23. }