Monday, May 28, 2012

ContentIterator Class in SharePoint 2010

In this article we will discuss about ContentIterator class which is introduced in SharePoint 2010 object model. Also you can check some SharePoint 2010 object model articles here.

- This class is introduced in SharePoint 2010 server object model.

- This class help us to manage large list in SharePoint 2010, also you can check another way to manage list using Query throttling. Whenever size of list increases we should optimize such a way that it will not affect performance of the site.

-Through this we can access more than 5,000 items (which is the default limit in SharePoint 2010 and 2000 is for MOSS 2007) in a large list without hitting a list throttling limit .

- We should only use ContentIterator class if we need to process large list whenever there is a chance to exceed a throttling limit.
- If it exceeds the list threshold limit it will give an exception SPQueryThrottleException.

- Namespace for ContentIterator is Microsoft.Office.Server.Utilities.ContentIterator

- Code Sample:

Void ProcessListItems()
           SPQuery listQuery = new SPQuery();
           CamlQuery query = new CamlQuery();
            query.ViewXml = "" + 
            listQuery.Query = query;
            SPList list = SPContext.Current.Web.Lists["MyList"];
            ContentIterator iterator = new ContentIterator();

public bool ProcessError(SPListItem item, Exception e)
            // Process the error
            return true;
        public void ProcessItem(SPListItem item)
            // Process the item

No comments:

Post a Comment