1

I am trying to delete items in bulk and keep getting this error message:

<Results><Result ID="" Code="-2130575312">
<ErrorText>Invalid file name.

The file name you specified could not be used.  It may be the name of an existing file or directory, or you may not have permission to access the file.</ErrorText></Result>
<Result ID="" Code="-2147023673">
<ErrorText>The operation failed because an unexpected error occurred. (Result Code: 0x800704c7)</ErrorText></Result>
<Result ID="" Code="-2147023673">

here is my batch xml:

<?xml version="1.0" encoding="UTF-8"?>
<Batch>
  <Method>
    <SetList>fe8ac4a1-c326-4a89-83ec-0793cdee943e</SetList>
    <SetVar Name="ID">1</SetVar>
    <SetVar Name="Cmd">Delete</SetVar>
  </Method>
  <Method>
    <SetList>fe8ac4a1-c326-4a89-83ec-0793cdee943e</SetList>
    <SetVar Name="ID">3</SetVar>
    <SetVar Name="Cmd">Delete</SetVar>
  </Method>
</Batch>

I used the code from here: https://gist.github.com/cakriwut/3b19fa7befedddb715f8

0

It works for me:

private void StartDeletion(SPWeb web, SPList spList)
{
    SPQuery query = new SPQuery();
    query.RowLimit = 1500;

    //Delete items                
    while (spList.ItemCount > 0)
    {
        SPListItemCollection collCities = spList.GetItems(query);
        string deletingBatch = BuildBatchDeleteCommand(spList, collCities);

        web.ProcessBatchData(deletingBatch);

        spList.Update();
    }
}

private string BuildBatchDeleteCommand(SPList list, SPListItemCollection coll)
{
    StringBuilder sbDelete = new StringBuilder();
    string batchFormat = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                            "<ows:Batch OnError=\"Continue\">{0}</ows:Batch>";


    StringBuilder batchBuilder = new StringBuilder();
    string command = String.Format("<Method><SetList>{0}</SetList><SetVar Name=\"ID\">{{0}}</SetVar><SetVar Name=\"Cmd\">Delete</SetVar></Method>", list.ID);
    foreach (SPListItem item in coll)
    {
        batchBuilder.AppendFormat(command, item.ID.ToString());
    }
    string fullBatch = string.Format(batchFormat, batchBuilder.ToString());
    return fullBatch;
}
  • Sorry, I forgot to mention that I am trying to achieve this with Powershell. – Aslan Aug 17 '16 at 12:57
  • Try to follow this link. Code in PS is similar to c#. – Semushin Dmitrii Aug 18 '16 at 3:40
0

I had to add this to my xml:

<SetVar Name=`"owsfileref`">{Path}</SetVar></Method>

{Path} = $list.ParentWeb.Url+"/"+$item.Url

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.