0

I am trying to run a batch process to insert items into a list. I am running into an error "Cannot complete action. Please try again." which I believe means that there is something wrong with my batch xml. This is my first time writing a batch for inserting items. I have a batch that deletes items without issue in the same block of code, so I am fairly certain the issue is with the xml.

StringBuilder batchString1 = new StringBuilder();
batchString1.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
batchString1.Append("<ows:Batch OnError=\"Return\">");
string destListID = destList.ID.ToString();
foreach (SPListItem item in items)
{
    batchString1.Append("<Method>");
    batchString1.Append("<SetList Scope=\"Request\">" + Convert.ToString(destListID) + "</SetList>");
    batchString1.Append("<SetVar Name=\"ID\">New</SetVar>");
    batchString1.Append("<SetVar Name=\"Cmd\">Save</SetVar>");
    batchString1.Append("<SetVar Name=\"urn:schemas-microsoft-com:office:office#Title\">Title here</SetVar>");
    batchString1.Append("</Method>");
}
batchString.Append("</ows:Batch>");
web.ProcessBatchData(batchString1.ToString());

Items is just an SPListItemCollection from a different list.

2
  • Have you checked the ULS logs for more details about the cause of the error? Nov 14 '13 at 17:52
  • Yes, my understanding was that it pointed to the same thing: at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx) at Microsoft.SharePoint.Library.SPRequest.ProcessBatchData(String bstrUrl, String bstrData, ISPDataCallback pResultCallback) at Microsoft.SharePoint.SPWeb.ProcessBatchData(String strBatchData) at CMSync.CMSync.Execute(Guid targetInstanceId) at Microsoft.SharePoint.Administration.SPTimerJobInvokeInternal.Invoke(SPJobDefinition jd, Guid targetInstanceId, Boolean isTimerService, Int32& result)
    – user11457
    Nov 14 '13 at 17:54
0

Stupid mistake. I never actually closed the xml. Last append is to a batchString variable instead of a batchString1 variable. I have to be less lazy about my naming.

batchString.Append("</ows:Batch>");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.