22 05 2009
SharePoint: SPList.Clear() extension method
Currently there is no good method in SharePoint for deleting all items from list. But there are solutions that need this kind of functionality. During one of my projects I wrote extension method for SPList that removes all items from it.
public static void Clear(this SPList list)
var count = list.ItemCount;
for (var i = count - 1; i >= 0; i--)
var item = list.GetItemById(i);
Feel free to use this code. Also let me know if I can make this code better somehow.