As you can see, quite clearly, it’s pretty impressive what the ContentIterator does when making such an expensive request to the database and making it inexpensive by dividing the query into small chunks.
Now I wanted to do something more common.. like looping through every sitecollection, it’s webs and it’s lists. Check out the following piece of code;
foreach (SPSite site in webApplication.Sites)
{
using (site)
{
foreach (SPWeb web in site.AllWebs)
{
using (web)
{
foreach (SPList list in web.Lists)
{
this.Controls.Add(new LiteralControl(list.Title.ToString()));
}
}
}
}
}
ContentIterator contentIterator = new ContentIterator();
contentIterator.ProcessSites(webApplication.Sites,
delegate(SPSite site)
{
ContentIterator contentIteratorWeb = new ContentIterator(contentIterator);
contentIteratorWeb.ProcessSite(site,
delegate(SPWeb web)
{
ContentIterator contentIteratorList = new ContentIterator(contentIteratorWeb);
contentIteratorList.ProcessLists(web.Lists,
delegate(SPList list)
{
this.Controls.Add(new LiteralControl(list.Title.ToString()));
},
delegate(SPList list, Exception error)
{
return true;
});
},
delegate(SPWeb web, Exception error)
{
return true;
});
},
delegate(SPSite site, Exception error)
{
return true;
});
}
The results are the following (and not quite shocking as the ListItems example is)