1 out of 1 rated this helpful - Rate this topic

SPWeb.ProcessBatchData Method

Windows SharePoint Services 3
Processes the specified batch string of commands for sending multiple requests to the server per transaction.

Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
public string ProcessBatchData (
	string strBatchData
)

Parameters

strBatchData

A Collaborative Application Markup Language (CAML) string that contains the batch string of commands, which consists of a Batch element and any number of subordinate Method elements that each specify a Windows SharePoint Services remote procedure call (RPC) method.

Return Value

A string that contains the results.

The following code example uses the ProcessBatchData method to add two items to the Announcements list of a specified site in the current site collection.

using (SPWeb oWebsite = SPContext.Current.Site.OpenWeb("Website_URL"))
{
    SPList oList = oWebsite.Lists["Announcements"];
    System.Guid guid = oList.ID;
    string strGuid = guid.ToString();

    string strPost = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
        "<ows:Batch OnError=\"Return\">" +
            "<Method ID=\"A1\"><SetList>" + strGuid + "</SetList>" +
                "<SetVar Name=\"ID\">New</SetVar>" +
                "<SetVar Name=\"Cmd\">Save</SetVar>" +
                "<SetVar Name=" +
                    "\"urn:schemas-microsoft-com:office:office#Title\">" +
                    "New Manager</SetVar>" +
                "<SetVar Name=" +
                    "\"urn:schemas-microsoft-com:office:office#Body\">" +
                    "Congratulations to Mary for her promotion!</SetVar>" +
                "<SetVar Name=" +
                    "\"urn:schemas-microsoft-com:office:office#Expires\">" +
                    "2003-09-14T00:00:00Z</SetVar>" + 
            "</Method>" +
            "<Method ID=\"A2\">" +
                "<SetList>" + strGuid + "</SetList>" +
                "<SetVar Name=\"ID\">New</SetVar>" +
                "<SetVar Name=\"Cmd\">Save</SetVar>" +
                "<SetVar Name=" +
                    "\"urn:schemas-microsoft-com:office:office#Title\">" +
                    "New Technical Consultant</SetVar>" +
                "<SetVar Name=" +
                    "\"urn:schemas-microsoft-com:office:office#Body\">" +
                    "Welcome to the team, John!</SetVar>" +
                "<SetVar Name=" +
                    "\"urn:schemas-microsoft-com:office:office#Expires\">" +
                    "2007-10-15T00:00:00Z</SetVar>" + 
            "</Method>" +
        "</ows:Batch>";

    string strProcessBatch = oWebsite.ProcessBatchData(strPost);
}
NoteNote:

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Best Practices: Using Disposable Windows SharePoint Services Objects.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Updating multi value fields using the ProcessBatchData method

If you need to update multi value fields (lookup, user or choice) using the ProcessBatchData method you can use the following format:

<?xml version="1.0" encoding="UTF-8"?>
<ows:Batch OnError="Continue">
<Method ID='1'>
<SetList>{0}</SetList>
<SetVar Name='Cmd'>Save</SetVar>
<SetVar Name='ID'>3</SetVar>
<SetVar Name='urn:schemas-microsoft-com:office:office#Location'>1;#;#2</SetVar>
<SetVar Name='urn:schemas-microsoft-com:office:office#Owners'>1;#;#7<</SetVar>
<SetVar Name='urn:schemas-microsoft-com:office:office#Choices'>Value1;#Value2</SetVar>
</Method>
</ows:Batch>


For the full coverage of the topic see this post:
http://pholpar.wordpress.com/2010/01/26/updating-multi-value-fields-using-web-service-call-and-batch-update/

How to create folders in SharePoint lists and the moderate command:
this is a sample XML that can be used to create a folder in a list with ProcessBatchData:

<?xml version="1.0" encoding="utf-8"?>
<ows:Batch OnError="Continue">
<Method ID="Test">
<SetList Scope="Request">82d62a9a-55ba-49c8-a9b8-68ec965a5931</SetList>
<SetVar Name="Cmd">Save</SetVar>
<SetVar Name="ID">New</SetVar>
<SetVar Name="Type">1</SetVar>
<SetVar Name="owsfileref">/sites/1/docs/folder1</SetVar>
</Method>
</ows:Batch>

And this is a sample XML to change the moderation status of a document (approve, reject, etc...)

<?xml version="1.0" encoding="UTF-8"?>
<ows:Batch OnError="Continue">
<Method ID="M0">
<SetList>82d62a9a-55ba-49c8-a9b8-68ec965a5931</SetList>
<SetVar Name="Cmd">Moderate</SetVar>
<SetVar Name="ID">26</SetVar>
<SetVar Name="owsfileref">/sites/1/docs/a.txt</SetVar>
<SetVar Name="owshiddenmodstatus">3</SetVar>
<SetVar Name="urn:schemas-microsoft-com:office:office#_ModerationStatus">0</SetVar>
<SetVar Name="owsitemlevel">2</SetVar>
<SetVar Name="_Level">2</SetVar>
<SetVar Name="owshiddenversion">12</SetVar>
</Method>
</ows:Batch>

for other tips you can check my blog - http://stefan-stanev-sharepoint-blog.blogspot.com/2009/07/tips-for-using-spwebprocessbatchdata.html.