Batch Updating List Items with SharePoint
In SharePoint, sometimes you must update multiple items in a list. Creating a foreach loop to iterate through a list item collection and performing an Update on each list item can be very intensive. An alternative approach is to construct a Collaborative Application Markup Language (CAML) string that contains a batch of commands to perform the updates and execute the commands by using the ProcessBatchData command of an SPWeb object. This example uses a document library named Processed Documents that contains a Processed yes/no field and Processed Date date field. You use a query to obtain a collection of items that have not been processed, as identified by their Processed value. You create a CAML statement to update the Processed and Processed Date fields for all documents in this library. After setting up the variables, you instantiate an SPList object for the Processed Documents document library by first instantiating an SPSite object and then an SPWeb ...