- private static void DeleteAllItemsUsingBatch()
- {
- using (SPSite site = new SPSite("http://mysharepointserver"))
- {
- SPWeb web = site.OpenWeb("/");
- SPList list = web.Lists["Documents"];
- 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><setvar name=\"owsfileref\">{1}</setvar></method>";
- foreach (SPListItem item in list.Items)
- {
- sb.AppendFormat(batchCommand, item.ID.ToString(), item.File.ServerRelativeUrl);
- }
- 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
Deleting all library items in a document library.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment