SharePoint几个操作
操作列表批量删除列表项
#region 批量删除 //查询出所要删除的列表项 query.Query = @"<Where><Eq><FieldRef Name='" + list.Fields["RoleID"].InternalName + @"'/> <Value Type='Text'>" + this.RoleID + "</Value></Eq></Where>"; //查询条件 SPListItemCollection items = list.GetItems(query);
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>"); //删除操作 sweb.ProcessBatchData(sbDelete.ToString()); #region 注释循环删除列表项 //for (int i = 0; i < items.Count; i++) //{ // //aa += items[i]["ModuleID"].ToString() + "<br>"; // //items[i].Delete(); // items[i].de(); //} #endregion
#endregion
循环添加列表项
#region 批量添加 string strModuleID = this.txt_ModuleID.Value.Trim(); if (!strModuleID.Equals("")) { SPListItem sListItem=null; string[] moduleIDList = strModuleID.Split(','); foreach (string moduleID in moduleIDList) { sListItem = list.Items.Add(); sListItem["aa"] = this.aa; sListItem["bb"] = bb; sListItem.Update(); } } #endregion
Linq查询几点(多表联合查询、In子查询、过滤重复记录)
this.PersonNameCollection = "小李,小王"; DataTable dtPerson = web.Lists["Person"].Items.GetDataTable(); DataTable dtCustion = web.Lists["Custion"].Items.GetDataTable(); DataTable dtPersonCustion = web.Lists["PersonCustion"].Items.GetDataTable(); var qList = (from Person in dtPerson.AsEnumerable() join PersonCustion in dtPersonCustion.AsEnumerable() on Person.Field<string>("PersonID") equals PersonCustion.Field<string>("PersonID") join Custion in dtCustion.AsEnumerable() on PersonCustion.Field<string>("CustionID") equals Custion.Field<string>("CustionCode") where this.PersonNameCollection.Contains(Person.Field<string>("Title")) //实现In子查询 orderby Custion.Field<string>("CustionCode") select new { ParentCustionID = PersonCustion.Field<string>("CustionID").Substring(0, 2), CustionID = PersonCustion.Field<string>("CustionID"), CustionName = Custion.Field<string>("Title"), CustionURL = Custion.Field<string>("URL") }).Distinct(); //并返回不重复记录

浙公网安备 33010602011771号