【发布时间】:2019-08-19 19:37:42
【问题描述】:
我在 Sharepoint 上 8000 多个列表上的 CAML 查询遇到了一些问题。我想对查询进行分页以避免此问题。我使用了这个 c# 代码:
List spList = clientContext.Web.Lists.GetByTitle(ConfigurationManager.AppSettings["ListaDocumenti"]);
clientContext.Load(spList);
clientContext.ExecuteQuery();
if (spList != null && spList.ItemCount > 0)
{
CamlQuery camlQuery = new CamlQuery();
string query = @"<View Scope='RecursiveAll'>
<QueryOptions><ViewAttributes Scope='Recursive'/></QueryOptions>
<RowLimit>1000</RowLimit>
<Query>
<Where>
<And>
<And>
<And>
<Eq>
<FieldRef Name='p_notifica' />
<Value Type='Boolean'>0</Value>
</Eq>
<Leq>
<FieldRef Name='p_DataPubblicazione' />
<Value IncludeTimeValue='false' Type='DateTime'>{0}</Value>
</Leq>
</And>
<IsNotNull>
<FieldRef Name='p_CodiceCliente' />
</IsNotNull>
</And>
<Eq>
<FieldRef Name='FSObjType' />
<Value Type='Integer'>0</Value>
</Eq>
</And>
</Where>
</Query>
</View>";
camlQuery.ViewXml = String.Format(query, date.AddDays(offset).ToString("s") + "Z"/*"2018-10-12T00:00:00Z"*/);
bool morerecords = false;
List<SPDocument> list_documents = new List<SPDocument>();
do
{
ListItemCollection listItems = spList.GetItems(camlQuery);
clientContext.Load(listItems);
clientContext.ExecuteQuery();
morerecords = listItems.Count == 1000;
list_documents.Add(...)
camlQuery.ListItemCollectionPosition = listItems.ListItemCollectionPosition;
} while (morerecords);
在生产环境中午餐这个查询(8000+项),它返回“尝试的操作被禁止,因为它超出了管理员强制执行的列表视图阈值”错误,在测试环境中一切正常(
如果我删除“Where”条件,它可以正常工作,但会返回整个列表(限制为 1000 个项目)。在启用“Where”条件的情况下,我可以尝试什么进行分页?
谢谢
【问题讨论】:
-
5000 还是 1000? C# 代码在哪里?您是否使用了 ListItemCollectionPosition 属性?
-
我已经编辑了添加 c# 代码的帖子
-
尝试索引您在
where子句中使用的列 -
我已经完成了对列的索引,但是没有用。
-
另一种选择是加载不带
<Where>子句的 ListItemCollection,然后使用 Linq 过滤它们
标签: c# sharepoint csom caml