Retrieve Only the Non Hidden Lists from SharePoint web using CSOM

  1. //using Microsoft.SharePoint.Client;  
  2. //using System.Net  
  3. //GetNonhiddenLists(credentials, weburl);  
  4.   
  5. //This method returns the lists from the web, which are visible to users  
  6. private static void GetNonhiddenLists(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.   
  14.         var listsQuery = from lst in lists  
  15.                                where lst.Hidden != true  
  16.                                select lst;  
  17.         IEnumerable<List> listcollection = ctx.LoadQuery(listsQuery);  
  18.         ctx.ExecuteQuery();  
  19.         Console.WriteLine("Non hidden Lists / Libraries: " + listcollection.Count().ToString());  
  20.         foreach (List lst in listcollection)  
  21.         {  
  22.             Console.WriteLine(lst.Title);  
  23.         }  
  24.     }  
  25.     Console.WriteLine("Press any key to exit...");  
  26.     Console.Read();  
  27. }