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


    先看代码:

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

  • 相关阅读:
    51nod 1051【基础】
    HDU5971【瞎搞】
    Lightoj1018 【状压DP】
    HDU2604【矩阵快速幂】
    HDU1501【简单DP】
    HDU3555【数位DP】
    Lightoj1037【状压DP】
    51nod 1099【贪心】
    HDU5950【矩阵快速幂】
    51nod 1049【经典】
  • 原文地址:https://www.cnblogs.com/springyangwc/p/1970183.html
Copyright © 2020-2023  润新知