SharePoint Online:使用 CSOM 获取文档库 Children 计数

SharePoint Online: Get Document Library Children Count Using CSOM

我的要求是使用 CSOM 获取文档库的 children 项计数。计数应该只是立即 children 计数,不应包括 sub-children 计数。我正在尝试使用以下代码来实现此目的:

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.

任何人都可以建议我如何在上面的步骤中获得 children 计数吗?

如果我对您的要求的解释正确,您想要文档库的根级子项计数吗?使用文档库 ItemCount 属性 RootFolder.

可以轻松实现这一点
var list = web.Lists.GetByTitle("Documents");
cc.Load(list.RootFolder, l => l.ItemCount);
cc.ExecuteQuery();

var rootChildItemCount = list.RootFolder.ItemCount;

或者您是否需要文档库中每个文件夹的子项目数?这可以通过 CamlQuery 来实现。如果您需要解决方案,请告诉我。