SharePoint Lists.asmx UpdateListItems: RootFolder

This week I read Jeffrey's post on how you can update a list item located in a sub folder using the RootFolder attribute on the UpdateListItems method of the Lists.asmx web service.

It seemed interesting enough to me to get this working in the U2U CAML Query Builder (windows version and feature version) so I started to implement it but I discovered that the truth about RootFolder is not as simple as it seems from this post.

Jeffrey states that the following code should work:

<Batch OnError="Continue" PreCalc="TRUE" ListVersion="0" RootFolder="Lists/Contacts/Work">
<Method ID="1" Cmd="Update">
<Field Name="ID">47821</Field>
<Field Name="RefID">479485</Field>
<Field Name="CustomerNumber">59613</Field>

I think that this code works because a valid ID is specified (in which case you even don't have to specify a RootFolder attribute: the item located in a sub folder can be updated specifying a valid ID). When I try this out without an ID I get an "Invalid URL" error.

The first thing I found out is that you have to make a difference between a list and a document library. In case of a list the root folder is indeed Lists, but you have to prefix it with a "/":

<Batch PreCalc="TRUE" OnError="Continue" RootFolder="/Lists/Cities/Europe/Belgium">
   <Method ID="1" Cmd="New">
      <Field Name="Title">Gent</Field>
      <Field Name="PostalCode">9000</Field>
      <Field Name="TelephoneZone">09</Field>

In case of a document library the root folder is the name of the document library, but it also needs to be prefixed with a "/":

<Batch PreCalc="TRUE" OnError="Continue"
    RootFolder="/Folders Doclib/2008/January">
   <Method ID="1" Cmd="New">
      <Field Name="Title">Document 2</Field>
      <Field Name="Income">2500</Field>

In case someone disagrees with this or if you have reasons to believe that even this is not complete, please let me know by posting a comment.

A new version of the U2U CAML Query Builder (windows version) will be ready to release end of this week. A new version of the feature version will be released a few weeks later. I keep you posted :)