首页 > 代码库 > SharePoint中删除列表记录
SharePoint中删除列表记录
方法1(快速,以理解,可以封装):
SPList spListQuestion = spWeb.Lists["Question List"]; for (int i = spListQuestion.Items.Count - 1; i >= 0; i--) { spListQuestion.Items[i].Delete(); }
方法2(繁琐):
SPList spListQuestion = spWeb.Lists["Question List"]; string sDIDTitle = spListQuestion.Fields["DID"].InternalName; SPQuery spQuery = new SPQuery(); spQuery.Query = "" + "" + spDocItem.ID.ToString() + ""; SPListItemCollection collListItems = spListQuestion.GetItems (spQuery); for (int i = 0; i < collListItems.Count; i++) { string ID = collListItems[i]["ID"].ToString(); SPItem spItem = spListQuestion.GetItemById (Int16.Parse (ID) ); spItem.Delete(); }
方法3(推荐):
SPList targetList = null; try { targetList = currentWeb.GetList (currentWeb.ServerRelativeUrl.TrimEnd (‘/‘) + listUrl); } catch { } if (targetList != null) { StringBuilder sbDelete = new StringBuilder(); sbDelete.Append ("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>"); foreach (SPItem item in targetList.Items) { if (item["Title"] != null) { sbDelete.Append ("<Method>"); sbDelete.Append ("<SetList Scope=\"Request\">" + targetList.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>"); try { currentWeb.ProcessBatchData (sbDelete.ToString() ); targetList.Update(); } catch (Exception ex) { } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。