Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
SharePoint 2010
SDK Documentation
Core Class Library
SPWeb Class
SPWeb Methods
 ProcessBatchData Method
Community Content
In this section
Statistics Annotations (3)
Collapse All/Expand All Collapse All
This page is specific to
The 2010 product release

Other versions are also available for the following:
SPWeb..::.ProcessBatchData Method

Processes the specified commands for sending multiple requests to the server per transaction.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
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
Type: System..::.String
A Collaborative Application Markup Language (CAML) that contains the commands, which consists of a Batch element and any number of subordinate Method elements that each specify a SharePoint Foundation remote procedure call (RPC) method.

Return Value

Type: System..::.String
The results of the processes.

To use this method to delete a document in a Document Library, pass the file path to the owsfileref variable in the Method elements.

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 Disposing Objects.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Exception: The operation failed because an unexpected error occurred      ArchaHim   |   Edit   |   Show History
Hi All,
I generated an XML string to be passed to ProcessBatchData function. The XML string looks like -
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<ows:Batch OnError=\"Return\">
<Method ID=\"Shadra, Himangi1\">
<SetList>d3106899-dd9d-485d-aa73-15a5c574483c</SetList>
<SetVar Name=\"ID\">New</SetVar>
<SetVar Name=\"Cmd\">Save</SetVar>
<SetVar Name=\"urn:schemas-microsoft-com:office:office#ContentType\">Task</SetVar>
<SetVar Name=\"urn:schemas-microsoft-com:office:office#Title\">Task -4</SetVar>
<SetVar Name=\"urn:schemas-microsoft-com:office:office#Order\">400</SetVar>
<SetVar Name=\"urn:schemas-microsoft-com:office:office#FileLeafRef\">4_.000</SetVar>
<SetVar Name=\"urn:schemas-microsoft-com:office:office#MetaInfo\"></SetVar>
<SetVar Name=\"urn:schemas-microsoft-com:office:office#Predecessors\"></SetVar>
<SetVar Name=\"urn:schemas-microsoft-com:office:office#Priority\">(2) Normal</SetVar>
<SetVar Name=\"urn:schemas-microsoft-com:office:office#Status\">Not Started</SetVar>
<SetVar Name=\"urn:schemas-microsoft-com:office:office#Body\"><div></div></SetVar>
<SetVar Name=\"urn:schemas-microsoft-com:office:office#StartDate\">2/1/2012 12:00:00 AM</SetVar>
<SetVar Name=\"urn:schemas-microsoft-com:office:office#Assigned To\">Shadra, Himangi</SetVar>
</Method> </ows:Batch>
The batch output is –
<Results><Result ID=\"Shadra, Himangi1\" Code=\"-2147352571\">\r\n<ErrorText>The operation failed because an unexpected error occurred. (Result Code: 0x80020005)</ErrorText></Result></Results>
The exception returned doesn’t give any idea on the problem. I checked SharePoint logs too; there is no helpful information in log 14. It just says - - - Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: Cannot complete this action. Please try again.
Any help in this is really appreciated.
Thanks.
Tags What's this?: Add a tag
Flag as ContentBug
How to use this in practice      Mr. Lars Nielsen   |   Edit   |   Show History
Here's an example using formatted strings to loop through updates to a large number of items: http://msdn.microsoft.com/en-us/library/cc404818(v=office.12).aspx
Tags What's this?: Add a tag
Flag as ContentBug
gnarly method, dude...      talarico   |   Edit   |   Show History
This just seems like an unmanageable way to demonstrate adding items through a batch process... Manually typing the XML is error prone, at the very least I would recommend some kind of helper method to make the code more readable - that's what developers would ultimately need to do, so providing a better example would be more helpful.
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker