Question

I have a big List which I want to empty. Therefore I create a template from that list, delete the list and create a new list from the template I just saved before.

I know there are other possibilities in deleting items from lists and also know of the drawbacks (especially regarding LookUps)

Now the threshold is too small and I do not want to change that in the central administration.

I also know I can override that threshold in Querys:

SPQuery q1 = new SPQuery();
q1.QueryThrottleMode = SPQueryThrottleOption.Override;

But I do not want to execute a SPQuery, but do the following:

listCopy.SaveAsTemplate(backupName, backupName, string.Empty, false);
listCopy.Delete();

(listCopy is an object of Type SPList)

Can I override the throttle there too? How? Or can I achieve the same (saving a template and deleting List) with SPQuery also?

Was it helpful?

Solution

If you use SharePoint Server 2010 and not SharePoint Foundtation you can enable SharePoint Publishing Infratstucture that will give you "Manage Content and Structure" there you can delete up to 1000 items at once.

You can also access "Manage Content and Structure" with the following url: http://www.yourservernamehere.com/_layouts/sitemanager.aspx

When you delete items there this causes a so called "Long Waiting Operation" which won't cause any timeout.

Another way is to use a powershell script to empty the list. I have a power shell script on my blog that used the ContentIterator to delete all versions of a document.

The ContentIterator is the best way to avoid the SPQueryThrotteling but shouldn't be used only for administrative tasks.

I'm sure you can use parts of this to delete all items from the list. http://www.n8d.at/blog/cleanup-item-and-file-versions-in-sharepoint-using-powershell/

There is no thotteling problem in this because it creates a on time timer job.

OTHER TIPS

Following Stefans instructions this is my (working) solution. Thanks

ContentIterator iterator = new ContentIterator();     
iterator.ProcessListItems(listCopy, string.Empty, true,                                                                                                   delegate(SPListItemCollection items)
    {
       for (int i=0; i<items.Count; i++)
       {
          items[i].Delete();
       }
    }, null

And it is quite fast compared to "normally" deleting those lines. );

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top