Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
    

4 Answers 4

up vote 2 down vote accepted

You can do batch deletes using SPWeb.ProcessBatchData method.

share|improve this answer

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;

    }
share|improve this answer

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

share|improve this answer
    
ThisI think would be the quickest and simplest solution. –  Paul T. Nov 9 '12 at 2:21

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.

share|improve this answer
    
But how we can use this on cs files ? –  Grzegorz Z Nov 29 '12 at 13:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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