Deleting all the list items from a list
I want to delete all the list items from the list. Is there any way to do that. I know it can be done by code. Can some one guide me how to do that. I dont want to delete the whole list and create a new one. So please guide me.
Thanks
November 12th, 2010 11:45am
you don't need to write code to do this, just switch to explorer view and delete all
from the library tab you should have an option called "Open with Explorer" try using that option to clear out all items
Microsoft Certified Master | SharePoint 2007
Blog
Free Windows Admin Tool Kit Click here and download it now
November 12th, 2010 12:13pm
Its not an document library. It is an sharepoint list.
November 12th, 2010 12:15pm
oops dint pay attention it was pre-sharepoint 2010 and custom list
Microsoft Certified Master | SharePoint 2007
Blog
Free Windows Admin Tool Kit Click here and download it now
November 12th, 2010 1:19pm
I know that, but I want to delete all of the list items. They are in thousands.
November 12th, 2010 2:20pm
You can select all, and it would take a while, but the datasheet view would work. You mentioned that you don't want to delete the list, but have you considered trying this? Save the list as a template
without content. Then use the blank template to create a new one. That way you wouldn't have to recreate all the columns.Laura Rogers, MCSE, MCTS
SharePoint911: SharePoint Consulting
Blog: http://www.sharepoint911.com/blogs/laura
Twitter: WonderLaura
Beginning SharePoint 2010: Building Business Solutions with SharePoint
Free Windows Admin Tool Kit Click here and download it now
November 12th, 2010 2:24pm
You could also try deleting those items using Access, add a linked table and use SharePoint List as data source (Option is under "External Data")
Microsoft Certified Master | SharePoint 2007
Blog
November 12th, 2010 2:41pm
Use this code
protected void Page_Load(object sender, EventArgs e)
{
SPSite site = new SPSite([Sharepoint Server]);
SPWeb web = site.OpenWeb();
web.AllowUnsafeUpdates = true;
SPList list = web.Lists[List Name];
deleteAllRerecords(list);
web.Update();
}
public void deleteAllRerecords(SPList list)
{
SPListItemCollection items = list.Items;
for (int i = items.Count - 1; i >= 0; i--)
{
items[i].Delete();
}
}
Free Windows Admin Tool Kit Click here and download it now
November 13th, 2010 1:22am
Hi ... Is there some more effective way how to do it ... I have a list with
thousands
of items ... and this way delete proximately one per second :(( So Is there another way how to do it in C# code ?? I was thinking about saving template, then delete list and recreate it from template.. It is possible ??? does somebody did it already to
save me some time. I would be nice Christmas present J
Thanks
December 23rd, 2010 4:36am
This is the best method to delete all items from the list:
StringBuilder sbDelete = new StringBuilder();
sbDelete.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>");
sbDelete.Append("<Batch>");
string command = "<Method><SetList Scope=\"Request\">" + spList.ID + "</SetList>";
command +="<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>");
spWeb.ProcessBatchData(sbDelete.ToString());
Please visit for more details: http://nileshmandekar.blogspot.com
Free Windows Admin Tool Kit Click here and download it now
March 13th, 2011 12:44pm