无法访问联系电话号码

时间:2016-04-07 14:07:20

标签: api exchange-server exchangewebservices

我使用EWS API访问联系人, 但无法访问联系电话号码!

初始提取中的view.Property看起来不接受ContactSchema.PhoneNumbers

目前我有:

        ItemView view = new ItemView(numItems);

        view.PropertySet = new PropertySet(BasePropertySet.IdOnly, new PropertyDefinitionBase[] { ContactSchema.DisplayName} );

        PropertySet PropSet = new PropertySet();
        PropSet.Add(ContactSchema.DisplayName);
        PropSet.Add(ContactSchema.PhoneNumbers);


        FindItemsResults<Item> findResults;

        do
        {
            findResults = service.FindItems(WellKnownFolderName.Contacts, view);

            if (findResults.Items.Count > 0)
            {
                service.LoadPropertiesForItems(findResults.Items, PropSet);
                foreach (var item in findResults.Items)
                {
                    // Display the list of contacts. 
                    if (item is Contact)
                    {
                        Contact contact = item as Contact;
                        PhoneNumberDictionary ph = contact.PhoneNumbers;
                        // ph is empty here!
                    }
                }
            }
            view.Offset += findResults.Items.Count;
        } while (findResults.MoreAvailable);

1 个答案:

答案 0 :(得分:2)

你几乎就是哥们只要添加你希望阅读/写入属性集的每个电话号码类型,你就得到了它!

Private ReadOnly PhoneFields As PropertySet = New  PropertySet(ContactSchema.PhoneNumbers, ContactSchema.MobilePhone, ContactSchema.CarPhone, ContactSchema.HomePhone,
                                                                  ContactSchema.HomePhone2, ContactSchema.HomePhone2, ContactSchema.BusinessPhone, ContactSchema.BusinessPhone2,
                                                                  ContactSchema.BusinessFax, ContactSchema.OtherFax, ContactSchema.HomeFax, ContactSchema.Pager,
                                                                  ContactSchema.OtherTelephone, ContactSchema.Callback, ContactSchema.CompanyMainPhone, ContactSchema.PrimaryPhone,
                                                                  ContactSchema.AssistantPhone, ContactSchema.RadioPhone, ContactSchema.TtyTddPhone, ContactSchema.Telex)

Etc等。

我刚刚建立了一个联系人同步Windows服务,任何问题都可以问我twittet @rojobo

相关问题