SharePoint批量删除SPListitem

SharePoint批量删除SPListitem

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public void DeleteData(SPListItemCollection items, SPList itemlist)
{
    SPSecurity.RunWithElevatedPrivileges(delegate()
    {
        using (SPSite site = new SPSite(itemlist.ParentWeb.Site.Url))
        {
            SPWeb web = site.OpenWeb(itemlist.ParentWeb.ID);
            SPList list = web.Lists[itemlist.ID];

            StringBuilder sbDelete = new StringBuilder();
            sbDelete.Append("<?xml version="1.0" encoding="UTF-8"?><Batch>");
            foreach (SPListItem item in items)
            {
                sbDelete.Append("<Method>");
                sbDelete.Append("<SetList Scope="Request">" + list.ID + "</SetList>");
                sbDelete.Append("<SetVar Name="ID">" + Convert.ToString(item.ID) + "</SetVar>");
                sbDelete.Append("<SetVar Name="Cmd">Delete</SetVar>");
                sbDelete.Append("</Method>");
            }
            sbDelete.Append("</Batch>");
            web.ProcessBatchData(sbDelete.ToString());
        }
    });
}

分享

文章导航