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();
}
}
No comments:
Post a Comment