SharePoint SPListWS.Lists 调用数据量过大时报错的处理方法

先看代码:

private SPListWS.Lists _ws;

private int _rowLimit = 100;

         //Add by spring yang
        /// 
        ///
        /// 
        /// 
        public void UpdateQARelateField(List listResults)
        {
            List 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 listResults)
        {
            StringBuilder xml = new StringBuilder();

            xml.Append("");
            foreach (SingleResultBE item in listResults)
            {

                if (!string.IsNullOrEmpty(item.ListItemId.ToString()) && (!string.IsNullOrEmpty(item.QARelate) || !string.IsNullOrEmpty(item.RelateBy)))
                {
                    xml.Append("");
                    xml.Append("" + item.ListItemId + "");
                    if (!string.IsNullOrEmpty(item.QARelate))
                    {
                        xml.AppendFormat("", item.QARelate);
                    }
                    if (!string.IsNullOrEmpty(item.RelateBy))
                    {
                        xml.AppendFormat("", item.RelateBy);
                    }
                    xml.Append("");
                }

            }
            xml.Append("");

            //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);
            }
        }
把数据分成每次100条分次处理就不会报 webservers错误了.

转载于:https://www.cnblogs.com/springyangwc/archive/2011/03/03/1970183.html

你可能感兴趣的:(SharePoint SPListWS.Lists 调用数据量过大时报错的处理方法)