c#-4.0 - Exchange Web 服务 - 更新联系人时出现错误代码 ErrorIn CorrectUpdatePropertyCount

标签 c#-4.0 exchangewebservices

我使用以下方法通过 EWS 更新 Exchange 中的联系人:

    private void UpdateContact(Microsoft.Exchange.WebServices.Data.Contact exContact, ContactInfo contact) {
        var pathList = new List<string>();
        try {
            log.DebugFormat("Process ExchangeContact '{0}' with Contact '{1}'", (exContact.IsNew ? "<new>" : exContact.DisplayName), contact.Id);

            exContact.GivenName = contact.AdditionalName;
            exContact.Surname = contact.Name;
            exContact.FileAsMapping = FileAsMapping.SurnameCommaGivenName;

            exContact.CompanyName = "";
            if (contact is PersonInfo) {
                var person = (PersonInfo) contact;
                if (person.PersonCompany != null && person.PersonCompany.Company != null) {
                    exContact.CompanyName = person.PersonCompany.Company.DisplayName;
                }
                exContact.ImAddresses[ImAddressKey.ImAddress1] = person.MessengerName;
                exContact.ImAddresses[ImAddressKey.ImAddress2] = person.SkypeName;
            }

            // Specify the business, home, and car phone numbers.
            var comm = contact.GetCommunication(Constants.CommunicationType.PhoneBusiness);
            exContact.PhoneNumbers[PhoneNumberKey.BusinessPhone] = (comm != null ? comm.Value : null);
            comm = contact.GetCommunication(Constants.CommunicationType.PhonePrivate);
            exContact.PhoneNumbers[PhoneNumberKey.HomePhone] = (comm != null ? comm.Value : null);
            comm = contact.GetCommunication(Constants.CommunicationType.PhoneMobile);
            exContact.PhoneNumbers[PhoneNumberKey.MobilePhone] = (comm != null ? comm.Value : null);

            comm = contact.GetCommunication(Constants.CommunicationType.MailBusiness);
            exContact.EmailAddresses[EmailAddressKey.EmailAddress1] = (comm != null ? new EmailAddress(comm.Value) : null);
            comm = contact.GetCommunication(Constants.CommunicationType.MailPrivate);
            exContact.EmailAddresses[EmailAddressKey.EmailAddress2] = (comm != null ? new EmailAddress(comm.Value) : null);

            // Specify two IM addresses.

            // Specify the home address.
            var address = contact.AddressList.FirstOrDefault(x => x.AddressType != null && x.AddressType.Id == Constants.AddressType.Private);
            if (address != null) {
                var paEntry = new PhysicalAddressEntry
                    {
                        Street = address.Street,
                        City = address.City,
                        State = address.Region,
                        PostalCode = address.PostalCode,
                        CountryOrRegion = address.CountryName
                    };
                exContact.PhysicalAddresses[PhysicalAddressKey.Home] = paEntry;
                if (contact.PostalAddress == address) {
                    exContact.PostalAddressIndex = PhysicalAddressIndex.Home;
                }
            } else {
                exContact.PhysicalAddresses[PhysicalAddressKey.Home] = null;
            }
            address = contact.AddressList.FirstOrDefault(x => x.AddressType != null && x.AddressType.Id == Constants.AddressType.Business);
            if (address != null) {
                var paEntry = new PhysicalAddressEntry
                    {
                        Street = address.Street,
                        City = address.City,
                        State = address.Region,
                        PostalCode = address.PostalCode,
                        CountryOrRegion = address.CountryName
                    };

                exContact.PhysicalAddresses[PhysicalAddressKey.Business] = paEntry;
                if(contact.PostalAddress == address) {
                    exContact.PostalAddressIndex = PhysicalAddressIndex.Business;
                }
            } else {
                exContact.PhysicalAddresses[PhysicalAddressKey.Business] = null;
            }

            // Save the contact.
            if (exContact.IsNew) {
                exContact.Save();
            } else {
                exContact.Update(ConflictResolutionMode.AlwaysOverwrite);
            }

            pathList.AddRange(this.AddFileAttachments(this.Access.IndependService.GetContact(exContact.Id.UniqueId), contact.GetDocuments()));
        } catch(Exception e) {
            log.Error("Error updating/inserting Contact in Exchange.", e);
        } finally {
            foreach (var path in pathList) {
                this.Access.Context.Container.Resolve<IDocumentService>().UndoCheckOut(path);
            }
        }
    }

当我执行此更新时,出现错误代码 ErrorIncorrectUpdatePropertyCount 的异常上线exContact.Update(ConflictResolutionMode.AlwaysOverwrite);

谁能帮帮我,有什么问题吗? - 谢谢。

最佳答案

解决方案是我必须检查字符串值是否为空字符串,在本例中设置为 null。这样,一切就正常了。

关于c#-4.0 - Exchange Web 服务 - 更新联系人时出现错误代码 ErrorIn CorrectUpdatePropertyCount,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9844610/

相关文章:

java - 使用 EWS Java API 检索预约的账单信息

c# - 如何使用一组笛卡尔坐标重复运行 .NET 单元测试

c#-4.0 - 在数据集中查找空值 - DataRow.IsNull 方法与 ==DbNull.Value - c#

entity-framework - 是否可以将 Entity Framework 与 Windows Azure 开发存储服务一起使用?

node.js - Node js 中的 EWS 推送通知

vb.net - 如何使用 EWS API 从嵌套电子邮件中获取文件附件

javascript - 在 iframe 中渲染电子邮件时如何处理 cid 图像源

c# - 为什么我们可以使用这样的任务?

c# - 为什么我们需要密封类?

c# - 使用 Oauth 和 full_access_as_user 对 EWS 进行身份验证