0

我的要求是使用CSOM獲取文檔庫的子項數。計數應該只是直接的孩子數,並且不應該包括子孩數。我試圖使用下面的代碼來實現這一點:SharePoint Online:獲取文檔庫使用CSOM的兒童數量

var newObjClientContext = this.GetSharePointClientContext(accessToken, fullUri); 
WebCollection collWeb = newObjClientContext.Web.GetSubwebsForCurrentUser(new SubwebQuery()); 
var documentLibrary = newObjClientContext.Web.Lists.GetById(docID); 

ListItemCollection ltitems = null; 

string vquery = @"<View > 
       <Query> 
        <Where> 
         <Or> 
          <Eq> 
           <FieldRef Name='FSObjType' /> 
           <Value Type='Lookup'>1</Value> 
          </Eq> 
          <Eq> 
           <FieldRef Name='FSObjType' /> 
           <Value Type='Lookup'>0</Value> 
          </Eq> 
          </Or> 
         </Where> 
         <OrderBy><FieldRef Name='FileLeafRef' Ascending='TRUE'></FieldRef></OrderBy>           
        </Query> 
        <RowLimit>" + recCount + @"</RowLimit> 
        </View>"; 

CamlQuery camlQuery = new CamlQuery(); 

camlQuery.ViewXml = vquery; 
ltitems = documentLibrary.GetItems(camlQuery); 
newObjClientContext.Load(documentLibrary); 
newObjClientContext.Load(ltitems, lists => lists.IncludeWithDefaultProperties(l => l.ParentList)); 

newObjClientContext.ExecuteQuery(); 

int totalcount = documentLibrary.ItemCount; //It includes count of all the items present at all levels. 

任何人都可以建議我怎麼能讓兒童算在上述步驟?

+0

你的意思是通過查詢選擇的項目數量? – tinamou

+0

不,上述查詢選擇的項目將受限於指定的「RowLimit」。我想獲得該文檔庫的總孩子數。 – Saket

+0

好吧,不可能。你想達到什麼目的?用分頁控制? – tinamou

回答

1

如果我已經正確解釋了您的需求,您希望文檔庫的根級別子項數?這很容易通過文檔庫RootFolderItemCount屬性來實現。

var list = web.Lists.GetByTitle("Documents"); 
cc.Load(list.RootFolder, l => l.ItemCount); 
cc.ExecuteQuery(); 

var rootChildItemCount = list.RootFolder.ItemCount; 

或者您是否需要文檔庫中每個文件夾的子項數?這可以通過CamlQuery來實現。讓我知道你是否需要這個解決方案。

相關問題