Using SPWeb.ProcessBatchData to Update Document Library Properties

Using SPWeb.ProcessBatchData to Update Document Library Properties

SharePoint offers a little-known but incredibly useful feature allowing for bulk adds, updates, and deletes of list items via the SPWeb.ProcessBatchData method. The usage is a bit complex because you need to pass CAML markup to the method to perform the operation on multiple list items. This CAML must contain the list item ID, list GUID, and relevant column names and values in an XML collection. There are numerous examples throughout the web showing how to write this CAML for manipulating list items in regular lists, but there is a quirk to manipulating document properties in a document library.

Upon successfully passing correct CAML to the ProcessBatchData method, the return value will be more CAML denoting which items were modified along with a code denoting the success of the operation on that item. A code of zero means success.

To my great frustration I was passing well-formed CAML to ProcessBatchData and receiving confirmation via the return object that my updates to document properties in a document library had been successful. However upon viewing the document library, the properties had not been updated.

To resolve this, I had to add an extra element to each Method tag. (A Method tag corresponds to an operation on a list item.) The element format is as follows.

<SetVar Name='owsfileref'>{0}</SetVar>

When formatting this string, pass the server-relative URL of the file associated with that list item, accessible via SPListItem.File.ServerRelativeUrl or if the item is a folder then SPListItem.Folder.ServerRelativeUrl. After passing in this additional element for each method, your operations should execute correctly on documents in document libraries.

Learn more about DMC's SharePoint consulting services.


# Ludo
Thanks ... you're post sill help people even 4 years later ...
# Minaj
Awesome! that works like a magic! ;) thanks. wondering how did you find about this trick, I barely can find any documentation about using SPWeb.ProcessBatchData method
# Piero
Yes! Thanks you very much!
# Developer
Sir , you are a genius!!
A1 Steak Sauce
For anyone else looking. The owsfileref field info can be found here:

Thanks for the post!
John Bellew
# John Bellew
Seriously man, 3 days of looking and your solution was most helpful. Thanks :)
Anwarali Hajwane
# Anwarali Hajwane
Great find !! Thanks.
# Adrian
You sir, are a legend.

Many Thanks
# NBDeveloper
Very helpful.

Post a comment

Name (required)

Email (required)

Enter the code shown above:

Related Blog Posts