【发布时间】:2017-07-27 13:55:49
【问题描述】:
我的要求是使用 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.
谁能建议我怎样才能让孩子在上述步骤中计数?
【问题讨论】:
-
你的意思是查询选择的项目的项目数吗?
-
否,上述查询选择的项目将受指定的“RowLimit”限制。我想获取该文档库的子项总数。
-
嗯,不可能。你想达到什么目的?用分页控制?
-
是的,出于同样的原因,我需要总计数,以便可以在 UI 中相应地显示页数。
-
所以你有两个选择,执行轻量级查询而不使用 rowlinit 或使用无限制的寻呼机。
标签: sharepoint csom sharepoint-clientobject