簡體   English   中英

SharePoint Online:使用CSOM獲取文檔庫子項計數

[英]SharePoint Online: Get Document Library Children Count Using CSOM

我的要求是使用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.

有人可以建議我如何讓孩子數入上述步驟嗎?

如果我正確解釋了您的要求,您是否希望文檔庫的根級子項計數? 使用文檔庫RootFolderItemCount屬性可以輕松實現這一點。

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

var rootChildItemCount = list.RootFolder.ItemCount;

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM