- private void DeleteAllItemsUsingBatch()
- {
- using (SPSite site = new SPSite("http://mySharePointServer"))
- {
- SPWeb web = site.OpenWeb("/");
- SPList list = web.Lists["Links"];
- StringBuilder sb = new StringBuilder();
- sb.Append("<batch>");
- string batchCommand = "<method><setlist scope=\"Request\">" + list.ID + "</setlist><setvar name=\"ID\">{0}</setvar><setvar name=\"Cmd\">DELETE</setvar></method>";
- foreach (SPListItem item in list.Items)
- {
- sb.Append(string.Format(batchCommand, item.ID.ToString()));
- }
- sb.Append("</batch>");
- web.AllowUnsafeUpdates = true;
- site.RootWeb.ProcessBatchData(sb.ToString());
- web.AllowUnsafeUpdates = false;
- web.Close();
- }
- }
The greatest test of courage on earth is to bear the defeat without losing heart..
Wednesday, December 1, 2010
To delete all the list items in a SharePoint list
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment