如何使用 Exchange WebService 将 CountryOrRegion 保存到联系人

How to save CountryOrRegion to a contact with Exchange WebService

我们下次要使用交换服务器,所以我想重新编码我们的联系人导入。

旧的使用Outlook.Interop库在定义的文件夹中创建联系人:


    Dim ci As ContactItem
    ci = f.Items.Add(OlItemType.olContactItem)
    ci.FirstName = ByNull(row("FirstName"))
    ci.LastName = ByNull(row("LastName"))
    ci.BusinessAddressCountry = ByNull(row("CountryName"))
    ci.Save()

但现在,我想通过 Exchange 托管保存联系人 API:


    Dim c As New Contact(svc)
    Dim pae As New PhysicalAddressEntry()

    pae.Street = ByNull(row("BusinessAddressStreet"))
    pae.PostalCode = ByNull(row("BusinessAddressPostalCode"))
    pae.City = ByNull(row("BusinessAddressCity"))
    pae.CountryOrRegion = ByNull(row("CountryName"))

    c.PhysicalAddresses(PhysicalAddressKey.Business) = pae
    c.PostalAddressIndex = PhysicalAddressIndex.Home 'fix, because it´s shown as business address
    c.Save()

它工作正常,除了 outlook 中 country/region 列中显示的国家/地区,因为它是空的。 (联系人->查看->列表)

截图: Outlook People

但是当我通过 Outlook 再次保存联系人时,国家/地区出现在列中。

我已经搜索了一些 属性,例如 Contact.CountryOrRegion,但这个不存在。

感谢您的帮助!

您还需要为此 属性 设置扩展的 pidTagCountry 属性 以显示在地址簿视图中 https://msdn.microsoft.com/en-us/library/ee201020(v=exchg.80).aspx

例如

        ExtendedPropertyDefinition PR_BUSINESS_ADDRESS_COUNTRY = new ExtendedPropertyDefinition(0x3A26, MapiPropertyType.String);
        ContactObject.SetExtendedProperty(PR_BUSINESS_ADDRESS_COUNTRY, "Australia");

强类型属性只设置这个pidLidWorkAddress属性https://msdn.microsoft.com/en-us/library/ee178066(v=exchg.80).aspx

干杯 格伦

网格(联系人->查看->列表)中显示的address/country/zip来自联系人的邮寄地址。您需要更新 3 个扩展属性以将这 3 个字段同步到联系人的邮寄地址:邮寄地址、Country/Region 和邮编。完整的代码片段是这样的:

//MAILING ADDRESS
ExtendedPropertyDefinition MAILING_ADDRESS = new ExtendedPropertyDefinition    (0x3A15, MapiPropertyType.String);
contact.SetExtendedProperty(MAILING_ADDRESS, "[Street][, City][, State/Province][ ZIP/Postal code][, Country/Region if not United States]");

//COUNTRY/REGION
ExtendedPropertyDefinition MAILING_ADDRESS_COUNTRY = new ExtendedPropertyDefinition(0x3A26, MapiPropertyType.String);
contact.SetExtendedProperty(MAILING_ADDRESS_COUNTRY, "[Country/Region]");

//ZIP/POSTAL CODE
ExtendedPropertyDefinition MAILING_ADDRESS_ZIP = new ExtendedPropertyDefinition(0x3A2A, MapiPropertyType.String);
contact.SetExtendedProperty(MAILING_ADDRESS_ZIP, "[ZIP/Postal code]");

这里的[]表示括号内指定的元素,如果该元素的值为空,则该元素将被省略。