If you have large set of content in the list and while accessing it using the CAML query, you might get the SPQueryThrottleException error or throttling limitation issue . To avoid such kind of situation, ContentIterator class can be used. This class implement a callback patter to divide the query, to process a single item at a time.
protected void TestIterator(object sender, EventArgs args)
{
TotalItems = 0; TotalExceptions = 0;
ContentIterator objContentIterator = new ContentIterator();
SPQuery objSPQuery = new SPQuery();
objSPQuery.Query = objString;SPList objList = SPContext.Current.Web.Lists["Employees"];
iterator.ProcessListItems(objList,objSPQuery, ProcessItem, ProcessError ); }
public bool ProcessError(SPListItem item, Exception e) { // process the errorTotalExceptions++;return true; }
public void ProcessItem(SPListItem item) {TotalItems++;//process the item. }
No comments:
Post a Comment