先看代码:
private SPListWS.Lists _ws; private int _rowLimit = 100; //Add by spring yang /// <summary> /// /// </summary> /// <param name="listResultsPart"></param> public void UpdateQARelateField(List<SingleResultBE> listResults) { List<SingleResultBE> listResultsPart = null; if (listResults != null && listResults.Count > 0) { for (int i = 0; i < listResults.Count / _rowLimit + 1; i++) { if (i == listResults.Count / _rowLimit) { listResultsPart = listResults.GetRange(i * _rowLimit, listResults.Count - i * _rowLimit); } else { listResultsPart = listResults.GetRange(i * _rowLimit, _rowLimit); } UpdateQARelateFieldLimit(listResultsPart); } } } private void UpdateQARelateFieldLimit(List<SingleResultBE> listResults) { StringBuilder xml = new StringBuilder(); xml.Append("<Batch OnError=\"Continue\">"); foreach (SingleResultBE item in listResults) { if (!string.IsNullOrEmpty(item.ListItemId.ToString()) && (!string.IsNullOrEmpty(item.QARelate) || !string.IsNullOrEmpty(item.RelateBy))) { xml.Append("<Method ID=\"" + item.ListItemId + "\" Cmd=\"Update\">"); xml.Append("<Field Name=\"ID\">" + item.ListItemId + "</Field>"); if (!string.IsNullOrEmpty(item.QARelate)) { xml.AppendFormat("<Field Name=\"QARelated\"><![CDATA[{0}]]></Field>", item.QARelate); } if (!string.IsNullOrEmpty(item.RelateBy)) { xml.AppendFormat("<Field Name=\"RelatedBy\"><![CDATA[{0}]]></Field>", item.RelateBy); } xml.Append("</Method>"); } } xml.Append("</Batch>"); //Get the Batch node XmlDocument doc = new XmlDocument(); doc.LoadXml(xml.ToString()); XmlNode batchNode = doc.SelectSingleNode("//Batch"); _logger.Log("Started batch update list Items' readonly fields"); XmlNode result = null; try { //Call the webservice result = _ws.UpdateListItems(Properties.ListName, batchNode); } catch (Exception ex) { //_logger.Log(String.Format("Error update Items. Exception: {0}. Stack Trace: {1}", ex.Message, ex.StackTrace)); } UpdateResultBE insertResult = new UpdateResultBE(result, Properties); if (Properties.IsNeedApprove) { this.ApproveItemsByInsertResult(insertResult); } }