SharePoint Harvester

Thursday, 13 November 2008 23:27 by RanjanBanerji

Often one has to write code to loop through all of SharePoint to make some sort of a sweeping change. Making such changes directly in the database is a bad idea and is not supported by Microsoft. So the best way to do so is to use the SharePoint WSS object model. SharePoint Harvester hopefully will make it easier to do so by providing a recursive traversal of a SharePoint application firing events when a site, list, item etc is found.

The SharePoint harvester code is really simple and can be accessed from  I am not going to start discussing the code itself.  Simple recursion and when webs, lists, items, etc are found it calls a virtual method and fires an event.  This way a user may choose to inherit from this class and override some methods or they can subscribe to relevant events.

So for example if you want to turn off versioning for every list in on every site in an application.  How would you do that?  You could go through the UI and browse to each site and each list and then turn off versioning for that list.  What if you had 500 sites each with 10 lists.  That is a lot of work.  Using SharePointHarvester you could do something like:

public void TurnOffVersioning() {
    SiteHarvester siteHarvester = new SiteHarvester();

    siteHarvester.Url = "http://some.sharepoint.url";
    siteHarvester.Recursive = true;

    siteHarvester.ListFound += new ListFoundHandler( siteHarvestor_ListFound );


void siteHarvestor_ListFound( object sender, ListFoundEventArg e ) {
    e._list.EnableVersioning = false;

You do not have to run this code for the entire application.  The URL you provide could easily have been for some sub site, for example:

siteHarvester.Url = "http://some.sharepoint.url/SomeSite/SomeSubSite";

Harvester will now only get lists for SomeSubSite and all its descendant sites.  As you can see, it makes life a lot easier instead of having to write the recursive code over and over.  More complex situations can now be handled.  For example what if you wanted to check-in all images that have been checked out across the entire application, or delete versions of all images because you are suffering from DB bloat.

More examples will follow.


Add comment

(Will show your Gravatar icon)

  Country flag

  • Comment
  • Preview