1

I have a list with about 500.000 thousand items. I need to delete all list items which created date is after a specific date.

The query would match about 450.000 thousand items. And then delete all of them.

Whats the fastest way to do it?

Luis Valencia
  • 5,201
  • 22
  • 118
  • 219
  • Possible duplicate: http://sharepoint.stackexchange.com/questions/26542/deleting-all-the-items-from-a-large-list-in-sharepoint and http://sharepoint.stackexchange.com/questions/39579/fastest-way-to-delete-all-items-with-c –  Nov 08 '12 at 15:10

4 Answers4

2

You can do batch deletes using SPWeb.ProcessBatchData method.

Nadeem Yousuf-AIS
  • 18,707
  • 4
  • 28
  • 59
1

Here Is good code for this:

       protected void Button1_Click(object sender, EventArgs e)
    {
        SPWeb witryna = SPContext.Current.Web;


        SPList list = witryna.Lists["Szczegoly"];
        StringBuilder sbDelete = BuildBatchDeleteCommand(list);
        witryna.ProcessBatchData(sbDelete.ToString());
    }

    private static StringBuilder BuildBatchDeleteCommand(SPList spList)
    {

        StringBuilder sbDelete = new StringBuilder();

        sbDelete.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>");

        string command = "<Method><SetList Scope=\"Request\">" + spList.ID +

        "</SetList><SetVar Name=\"ID\">{0}</SetVar><SetVar Name=\"Cmd\">Delete</SetVar></Method>";


        foreach (SPListItem item in spList.Items)
        {

            sbDelete.Append(string.Format(command, item.ID.ToString()));

        }

        sbDelete.Append("</Batch>");

        return sbDelete;

    }
Grzegorz Z
  • 1,709
  • 7
  • 42
  • 73
1

Another option would be connecting to the list via Access and running a delete query against the list.

Eric Alexander
  • 43,293
  • 10
  • 53
  • 93
0

You can write a small jQuery-snippet with SPServices, This forum post seems to work, so just change the listname and the CAML Query according to your criteria.

curmudgeon
  • 486
  • 1
  • 3
  • 12