SPWeb.ProcessBatchData Method (Microsoft.SharePoint)
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)
Syntax

Visual Basic (Declaration)
Public Function ProcessBatchData ( _
    strBatchData As String _
) As String
Visual Basic (Usage)
Dim instance As SPWeb
Dim strBatchData As String
Dim returnValue As String

returnValue = instance.ProcessBatchData(strBatchData)
C#
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.
Example

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.

Visual Basic
Using webSite As SPWeb = SPContext.Current.Site.OpenWeb("Website")
    Dim list As SPList = webSite.Lists("Announcements")

    Dim guid As System.Guid = list.ID
    Dim myGuid As String = guid.ToString()

    Dim strPost As String = "<?xml version='1.0' encoding='UTF-8'?>" _
        & "<ows:Batch OnError='Return'>" _ 
        & "<Method ID='A1'>" _
            & "<SetList> & myGuid & "</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>" & myGuid & "</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'>" _
                & "2003-10-15T00:00:00Z</SetVar></Method></ows:Batch>"

    Dim processBatch As String = webSite.ProcessBatchData(strPost)
End Using
C#
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.

See Also

Tags :


Community Content

Stefan Stanev
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.

Page view tracker