Thursday, December 5, 2013

Content Iterator in SharePoint

In SharePoint object model while getting the data from large lists through SPQuery, we can get SPQueryThrottleException saying that “The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator”. We can get rid of this exception by using Content Iterator (CI). Content Iterator provides implementation interface for SharePoint objects to regularize the amount of data to be transferred. This will helps queries in on the lists to not put the load on database excessively. It will iterate the content in the list instead of executing the query. So that it will process each item in the list to avoid the throttling limits.

We can process the content iterator to crawl the list items. Following is the sample code will give us the detail about Content Iterator processing

public static void ProcessListItems(SPWeb site)
{ 
string iteratorName = "item iterator"; 
ContentIterator iterator = new ContentIterator(iteratorName);

iterator.ProcessLists(site.Lists,
delegate(SPList list){ 
ContentIterator.EnsureFieldIndexed(list, list.Fields.GetFieldByInternalName("Title").Id);
string query = "<Where><And><BeginsWith><FieldRef Name='Title' /><Value Type='Text'></Value>RT</BeginsWith></And></Where>"; 
ContentIterator itemsIterator = new ContentIterator(iterator);
itemsIterator.ProcessListItems(list,query,true,
delegate(SPListItemCollection items){
foreach (SPListItem item in items){
ProcessItem(item);
}
},null);
},
delegate(SPList list, Exception e)
{
OnListException(list, e);
});
}



Share this

0 Comment to "Content Iterator in SharePoint"

Post a Comment