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?

1

4 Answers 4

2

You can do batch deletes using SPWeb.ProcessBatchData method.

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;

    }
1

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

1
  • ThisI think would be the quickest and simplest solution.
    – Paul T.
    Nov 9, 2012 at 2:21
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.

1
  • But how we can use this on cs files ?
    – Grzegorz Z
    Nov 29, 2012 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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