SharePoint 2010批量更新错误

本文关键字:错误 更新 2010批 SharePoint | 更新日期: 2023-09-27 18:03:52

我正在从csv文件中上传数据,该文件有大约200k条记录到sharepoint列表,代码工作正常,但我在代码运行约2小时左右后得到此错误。

无法完成此操作。

请重试。在Microsoft.SharePoint.SPGlobal。HandleComException (COMException comEx)
在Microsoft.SharePoint.Library.SPRequest.ProcessBatchData(字符串bstrUrl, String bstrData, ISPDataCallback pResultCallback) atMicrosoft.SharePoint.SPWeb。ProcessBatchData(String strBatchDataUploadIrisData.Program.Dof1FieldsBatchUpdate [T] (IEnumerable"1成员列表,SPList列表,StringBuilderSPQuery查询,String createquery, String batchFormatHandleComException at offset 27818482 in file:line:column:0:0

  private static void Dof1FieldsBatchUpdate<T>(IEnumerable<T> memberList, SPList list, StringBuilder methodBuilder, SPWeb web,
        SPQuery query, string createquery, string batchFormat)
    {
        string batch = String.Empty;
        string listGuid = list.ID.ToString();
        List<f1fields> f1Fieldses = (List<f1fields>)memberList;
        query.Query = "<Where>" + CreateDynamicQuery<T>(memberList.ToList(), createquery) + "</Where>";
        query.ViewAttributes = "Scope='Recursive'";
        query.RowLimit = 1000;
        try
        {
            do
            {
                SPListItemCollection items = list.GetItems(query);
                string methodFormat = "<Method ID='"{0}'">" +
                            "<SetList>{1}</SetList>" +
                            "<SetVar Name='"Cmd'">Save</SetVar>" +
                            "<SetVar Name='"ID'">{2}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#Title'">{3}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLContractNumber'">{4}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLClubName'">{5}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLEmailHome'">{6}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLEmailWork'">{7}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLFaxNumber'">{9}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLHomePhone'">{10}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLIDNumber'">{11}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLLegalCategory'">{12}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLMemberEffectiveYear'">{13}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLMemberName'">{14}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLMemberStatus'">{15}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLPassportNumber'">{16}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLPasswordRequired'">{17}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLPhysicalHomeAddress1'">{18}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLPhysicalHomeAddress2'">{19}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLPhysicalHomeAddress3'">{20}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLPhysicalHomeAddress4'">{21}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLPhysicalHomePostalCode'">{22}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLPhysicalWorkAddress1'">{23}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLPhysicalWorkAddress2'">{24}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLPhysicalWorkAddress3'">{25}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLPhysicalWorkAddress4'">{26}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLPhysicalWorkPostalCode'">{27}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLPostalHomeAddress1'">{28}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLPostalHomeAddress2'">{29}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLPostalHomeAddress3'">{30}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLPostalHomeAddress4'">{31}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLPostalHomePostalCode'">{32}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLWorkPhone'">{33}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLCompanyKey'">{34}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLPostalWorkAddress1'">{35}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLPostalWorkAddress2'">{36}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLPostalWorkAddress3'">{37}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLPostalWorkAddress4'">{38}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLPostalWorkPostalCode'">{39}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLCellphone'">{40}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLAnnualFeesTotalOverdue'">{41}</SetVar>" +
                            "<SetVar Name='"urn:schemas-microsoft-com:office:office#CLContractTotalOverdue'">{42}</SetVar>" +
                            "</Method>";
                var excludedMemberIDs = new HashSet<string>(f1Fieldses.Select(r => r.MemberNumber));
                var memberNumbersFoundInList = new List<string>();
                //build the CAML update commands
                if (items.Count > 0)
                {
                    for (var i = 0; i < items.Count; i++)
                    {
                        var memberId = items[i].ID;
                        memberNumbersFoundInList.Add(items[i].Title);
                        int i1 = i;
                        foreach (var member in f1Fieldses.Where(member => items[i1].Title == member.MemberNumber))
                        {
                            methodBuilder.AppendFormat(methodFormat, memberId, listGuid, memberId,
                                member.MemberNumber, member.ContractNumber, member.ClubName, member.EmailHome, member.EmailWork,
                                member.HistoricalNumber, member.FaxNumber, member.HomePhone, member.IdNumber, member.LegalCategory,
                                member.MemberEffectiveYear, member.MemberName, member.MemberStatus,
                                member.PassportNumber, member.PasswordRequired, member.PhysicalHomeAddress1,
                                member.PhysicalHomeAddress2, member.PhysicalHomeAddress3,
                                member.PhysicalHomeAddress4, member.PhysicalHomePostalCode,
                                member.PhysicalWorkAddress1, member.PhysicalWorkAddress2,
                                member.PhysicalWorkAddress3, member.PhysicalWorkAddress4,
                                member.PhysicalWorkPostalCode,
                                member.PostalHomeAddress1, member.PostalHomeAddress2, member.PostalHomeAddress3,
                                member.PostalHomeAddress4, member.PostalHomePostalCode, member.WorkPhone, member.CompanyKey,
                                member.PostalWorkAddress1, member.PostalWorkAddress2, member.PostalWorkAddress3, member.PostalWorkAddress4,
                                member.PostalWorkPostalCode, member.CellPhone, member.AnnualFeesTotal, member.ContractTotalOverdue
                                );
                        }
                        //memberToWriteToLog.Add(items[i].Title);
                    }
                }
                var result = f1Fieldses.Where(p => !memberNumbersFoundInList.Contains(p.MemberNumber));
                IEnumerable<f1fields> f1FieldsesUpdateNew = result as IList<f1fields> ?? result.ToList();
                //if (f2FieldsesUpdateNew.Any()) Debugger.Break();
                // New member numbers to be add to the list
                var newMembersWithoutDuplicates = new List<f1fields>();
                var duplicatesMemberNumber = new List<f1fields>();
                //Find duplicates before batch update
                foreach (var s in f1FieldsesUpdateNew)
                {
                    var temp = newMembersWithoutDuplicates.Find(x=>x.MemberNumber.Contains(s.MemberNumber));
                    if (temp == null)
                        newMembersWithoutDuplicates.Add(s);
                    else
                    {
                        duplicatesMemberNumber.Add(s);
                    }
                }

                if (newMembersWithoutDuplicates.Any())
                {
                    var memberId = 1;
                    foreach (var member in newMembersWithoutDuplicates)
                    {
                        methodBuilder.AppendFormat(methodFormat, memberId, listGuid, "New",
                                member.MemberNumber, member.ContractNumber, member.ClubName, member.EmailHome, member.EmailWork,
                                member.HistoricalNumber, member.FaxNumber, member.HomePhone, member.IdNumber, member.LegalCategory,
                                member.MemberEffectiveYear, member.MemberName, member.MemberStatus,
                                member.PassportNumber, member.PasswordRequired, member.PhysicalHomeAddress1,
                                member.PhysicalHomeAddress2, member.PhysicalHomeAddress3,
                                member.PhysicalHomeAddress4, member.PhysicalHomePostalCode,
                                member.PhysicalWorkAddress1, member.PhysicalWorkAddress2,
                                member.PhysicalWorkAddress3, member.PhysicalWorkAddress4,
                                member.PhysicalWorkPostalCode,
                                member.PostalHomeAddress1, member.PostalHomeAddress2, member.PostalHomeAddress3,
                                member.PostalHomeAddress4, member.PostalHomePostalCode, member.WorkPhone, member.CompanyKey,
                                member.PostalWorkAddress1, member.PostalWorkAddress2, member.PostalWorkAddress3, member.PostalWorkAddress4,
                                member.PostalWorkPostalCode, member.CellPhone, member.AnnualFeesTotal, member.ContractTotalOverdue
                                );
                        memberId++;
                    }
                }
                web.AllowUnsafeUpdates = true;
                batch = string.Format(batchFormat, methodBuilder.ToString());
                // Process the batch of commands
                web.ProcessBatchData(batch);
                //web.AllowUnsafeUpdates = false;
                methodBuilder.Length = 0;
                if (duplicatesMemberNumber.Any())
                {
                    SPQuery query2 = new SPQuery();
                    string createquery2 = "";
                    Dof1FieldsBatchUpdate(duplicatesMemberNumber, list, methodBuilder, web, query2, createquery2, batchFormat);
                }
            } while (query.ListItemCollectionPosition != null);
        }
        catch (Exception ex)
        {
            using (FileStream fs = new FileStream("c:''error.txt", FileMode.Append, FileAccess.Write))
            using (StreamWriter sw = new StreamWriter(fs))
            {
                // Get stack trace for the exception with source file information
                var st = new StackTrace(ex, true);
                // Get the top stack frame
                var frame = st.GetFrame(0);
                // Get the line number from the stack frame
                var line = frame.GetFileLineNumber();
                sw.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine + frame + Environment.NewLine + line);
            }
        }
    }

SharePoint 2010批量更新错误

我有同样的异常,原因是一个未转义的<div>标记破坏了xml结构。确保您的数据正确插入<SetVar>标签。

如果不是这样的话,我读过,太大的批量更新xml可能会导致异常。