Translate

Wednesday, September 19, 2012

Using SPQuery with ContentIterator.MaxItemsPerQuery in SharePoint

Using SPQuery with ContentIterator.MaxItemsPerQuery



1.       Using SPQuery with RowLimit or with ContentIterator.MaxItemsPerQuery
When we query the SharePoint list and libraries we use SPQuery and some situations because of threshold value limit in sharepoint does not allow the user to query more than or equal to 5000 items,If we use SPQuery  with RowLimit still it is not sure to get the items, but  there is still SharePoint has provide one more way can do it through using ContentIterator.MaxItemsPerQuery.

We also need to use different keywords using depends upon the requirement ContentIterator.ItemEnumerationOrderByID, ContentIterator.ItemEnumerationOrderByPath, or ContentIterator.ItemEnumerationOrderByNVPField.

Sample Code


SPQuery myQuery = new SPQuery();
myQuery.Query =
"<Where><Eq><FieldRef Name=\"Name\"/><Value Type=\"Text\">FieldValue</Value></Eq></Where>"
+ ContentIterator. ItemEnumerationOrderByID;
ContentIterator citerator = new ContentIterator();
citerator.ProcessItemsInList(query,
    delegate(SPListItem item)
    {
        // Code for update or move the list item from one list to another or    //any operation
    },
   // Return true so that ContentIterator rethrows the exception.
    delegate(SPListItem item, Exception e)
    {
        // Handle an exception that was thrown while iterating.
        return true;
    }
);




No comments:

Post a Comment