我想要查询的列表中有大约 10000 多行(Listitems)。
我想迭代timerJob中的每个项目 - 但我不能一次获取所有项目 因为:对象模型覆盖 - 否,ListView 阈值 - 1000 - 在 FARM 级别,我们无法更改此设置。
我有什么方法可以迭代所有 10000+(就像一个批处理)??
最佳答案
您应该使用 ContentIterator 。这将允许您迭代非常大的列表的内容,而不会触发 SPQueryThrottledException
。
例如:
SPList list = SPContext.Current.Web.Lists["MyList"];
// Build query using an iterator-defined WHERE clause
string query = string.Format("<Where><Eq><FieldRef Name='MyFieldName'/><Value Type='Text'>MyFieldValue</Value></Eq></Where>{0}", ContentIterator.ItemEnumerationOrderByNVPField);
// Instantiate iterator and use it to process the list
ContentIterator iterator = new ContentIterator();
iterator.ProcessListItems(list, query, ProcessListItem, ProcessListItemError);
然后您可以这样定义您的 ProcessListItem
和 ProcessListItemError
:
static void ProcessListItem(SPListItem item) {
Console.WriteLine("ProcessListItem: Name {0}", item.Title);
}
static bool ProcessListItemError(SPListItem item, Exception e) {
Console.WriteLine("ERROR: message {0}", e.Message);
return true;
}
我还建议您查看 Microsoft 的 Best Practices with SharePoint Server articles ,特别是“Writing Efficient Code In SharePoint Server ”,它进一步讨论了正确编写查询的方法。
关于sharepoint - SPQuery 和 RowLimit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5823267/