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 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?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer
    
I have no Access to the powershell. The ContentIterator seems nice, but because I have to iterate through each element using "foreach item in" I cannot delete that item (item.Delete()) there. (correct me if I am wrong) –  Ole Albers Aug 9 '12 at 15:23
    
You can always use instead of a foreach an old school for loop and in there you should be able to delete the items. –  Stefan Bauer Aug 9 '12 at 15:31
    
Found my mistake. I used list.Items.DeleteById() instead of directly deleting the item. Will add that as an answer. Your answer led the way. So thanks :) –  Ole Albers Aug 9 '12 at 15:46

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. );

share|improve this answer

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.