2015-10-06 77 views
0

我正在使用SharePoint 2013並嘗試返回站點URL中存在的所有列表。我試過下面的代碼,但它返回一個初始化錯誤。我該如何正確地返回這些列表?在SharePoint 2013中返回列表CSOM

foreach (List li in clientContext.Web.Lists) 
     { 
      Console.WriteLine(li.Title); 
     } 
     Console.Read(); 

回答

0

我想出了我自己的想法。需要創建一個新的ListCollection,然後在調用ExecuteQuery後,從SharePoint服務器上拉下的ListCollection可以填充到它。見下面的例子。

ListCollection lc = clientContext.Web.Lists; 
clientContext.Load(lc); 
clientContext.ExecuteQuery(); 

foreach (List l in lc) 
    { 
     { 
      //Do work here 
     } 
    } 
相關問題