locked
Deleting Items using ProcessBatchData method

    Question

  • I'm trying to delete all items from a list using ProcessBatchData but I'm getting the error message : "<nativehr>0x80070057</nativehr><nativestack></nativestack>".

    The original List contains a couple of lookup fields, I thought that it was the problem, but, like a concept proof, I've created a simple list with no other fields than Title and I'm getting the same error.

    The last proof was made with this XML :

    <Batch OnError="Continue">
      <Method ID="Del8">
      <SetList Scope="Request">e6068b37-003f-4877-962b-7e8e0b79e786</SetList> 
     <SetVar Name="Cmd">Delete</SetVar> 
     <SetVar Name="ID">8</SetVar> 
     </Method>
     <Method ID="Del10">
     <SetList Scope="Request">e6068b37-003f-4877-962b-7e8e0b79e786</SetList> 
     <SetVar Name="Cmd">Delete</SetVar> 
     <SetVar Name="ID">10</SetVar> 
     </Method>
     </Batch>
    

    There are some restrictions or I have to active some feature in the server, or something else in order to use this method?.

    Is the XML wrong formatted or I'm missing somthing?

     

    Thanks in advantage.

    Tuesday, March 08, 2011 8:47 PM

Answers

  • I've done this before and it perfectly works for me -

    static void Main(string[] args)
            {
                SPSite site = new SPSite("http://site01");
                SPWeb web = site.OpenWeb();
                string batchFormat = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                "<ows:Batch OnError=\"Return\">{0}</ows:Batch>";

                string processtext = @"<Method ID=""Del8"">
                                     <SetList Scope=""Request"">5a322841-85cb-4782-bb06-28b7c44b214b</SetList>
                                     <SetVar Name=""Cmd"">Delete</SetVar>
                                     <SetVar Name=""ID"">1</SetVar>
                                     </Method>
                                     <Method ID=""Del10"">
                                     <SetList Scope=""Request"">5a322841-85cb-4782-bb06-28b7c44b214b</SetList>
                                     <SetVar Name=""Cmd"">Delete</SetVar>
                                     <SetVar Name=""ID"">2</SetVar>
                                     </Method>
                                    ";

                processtext = string.Format(batchFormat, processtext);

                web.ProcessBatchData(processtext);
            }


    NLV - MCTS - Blog - Twitter
    • Marked as answer by Porter Wang Thursday, March 10, 2011 7:00 AM
    Wednesday, March 09, 2011 5:51 AM
  • using(SPSite spSite = new SPSite("site url"))
    {
    using(SPWeb spWeb = spSite.OpenWeb())
    {
    
    sbDelete.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"? >");
    sbDelete.Append("<ows:Batch OnError=\"Return\">");
    sbDelete.Append("<Method>");
    sbDelete.Append("<SetList Scope=\"Request\">" + CurrentList.ID + "</SetList>");
    sbDelete.Append("<SetVar Name=\"ID\">" + Convert.ToString(item.ID) + "</SetVar>");
    sbDelete.Append("<SetVar Name=\"Cmd\">Delete</SetVar>");
    sbDelete.Append("</Method>");
    spWeb.ProcessBatchData(sbDelete.ToString());
    }
    }
    

    CurrentList.ID - guid of the SharePoint list from where items will be deleted.

    item.ID - unique id of the item which will be deleted.

    hope this will help...


    thanksArup MCTS - SharePoint

    Play Sudoku Online
    • Marked as answer by Porter Wang Thursday, March 10, 2011 7:00 AM
    Wednesday, March 09, 2011 6:41 AM

All replies

  • I've done this before and it perfectly works for me -

    static void Main(string[] args)
            {
                SPSite site = new SPSite("http://site01");
                SPWeb web = site.OpenWeb();
                string batchFormat = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                "<ows:Batch OnError=\"Return\">{0}</ows:Batch>";

                string processtext = @"<Method ID=""Del8"">
                                     <SetList Scope=""Request"">5a322841-85cb-4782-bb06-28b7c44b214b</SetList>
                                     <SetVar Name=""Cmd"">Delete</SetVar>
                                     <SetVar Name=""ID"">1</SetVar>
                                     </Method>
                                     <Method ID=""Del10"">
                                     <SetList Scope=""Request"">5a322841-85cb-4782-bb06-28b7c44b214b</SetList>
                                     <SetVar Name=""Cmd"">Delete</SetVar>
                                     <SetVar Name=""ID"">2</SetVar>
                                     </Method>
                                    ";

                processtext = string.Format(batchFormat, processtext);

                web.ProcessBatchData(processtext);
            }


    NLV - MCTS - Blog - Twitter
    • Marked as answer by Porter Wang Thursday, March 10, 2011 7:00 AM
    Wednesday, March 09, 2011 5:51 AM
  • using(SPSite spSite = new SPSite("site url"))
    {
    using(SPWeb spWeb = spSite.OpenWeb())
    {
    
    sbDelete.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"? >");
    sbDelete.Append("<ows:Batch OnError=\"Return\">");
    sbDelete.Append("<Method>");
    sbDelete.Append("<SetList Scope=\"Request\">" + CurrentList.ID + "</SetList>");
    sbDelete.Append("<SetVar Name=\"ID\">" + Convert.ToString(item.ID) + "</SetVar>");
    sbDelete.Append("<SetVar Name=\"Cmd\">Delete</SetVar>");
    sbDelete.Append("</Method>");
    spWeb.ProcessBatchData(sbDelete.ToString());
    }
    }
    

    CurrentList.ID - guid of the SharePoint list from where items will be deleted.

    item.ID - unique id of the item which will be deleted.

    hope this will help...


    thanksArup MCTS - SharePoint

    Play Sudoku Online
    • Marked as answer by Porter Wang Thursday, March 10, 2011 7:00 AM
    Wednesday, March 09, 2011 6:41 AM
  • That works, thanks to all.

     

     

    Thursday, March 10, 2011 1:33 PM