我正在使用办公室(Microsoft.Exchange.WebServices
)获取有关office365上联系人的数据。
我正确地获取了所有信息,除了来自电子邮件地址的名字。它们是空的。
我想我忘记了一个PropertySet,但我不知道哪一个。
所以这是我得到的数据的打印屏幕。如您所见,Id,MailboxType,Name和RoutingType都为null。
这是我调用以获取数据的函数:
public ContactInConexio[] GetAll()
{
Debugger.Launch();
var contactsFolder = ContactsFolder.Bind(_service, WellKnownFolderName.Contacts,
new PropertySet(BasePropertySet.IdOnly, FolderSchema.TotalCount));
var numItems = contactsFolder.TotalCount;
if (numItems > 0)
{
var view = new ItemView(numItems) { PropertySet = _contactPropertySet };
view.PropertySet = _contactPropertySet;
//SearchFilter filter = new SearchFilter.Exists(ContactSchema.CompanyName);
//This is the variable where I put the breakpoint. And the data of contactsItem is in the picture.
var contactsItems = contactsFolder.FindItems(view);
var officeContacts =
new List<ContactInOffice>(Array.ConvertAll(contactsItems.ToArray(), x => (ContactInOffice)x));
return Array.ConvertAll(officeContacts.ToArray(),
officeContact => officeContact.ToConexioContact(new ContactInConexio()));
}
return new ContactInConexio[0];
}
这是PropertySet:
private readonly PropertySet _contactPropertySet = new PropertySet(BasePropertySet.IdOnly,
ContactSchema.DisplayName,
ContactSchema.CompleteName, ContactSchema.CompanyName, ContactSchema.Department, ContactSchema.JobTitle,
ContactSchema.Profession, ContactSchema.BusinessHomePage, ContactSchema.Birthday, ContactSchema.Photo,
ContactSchema.HasPicture,
ContactSchema.PrimaryPhone, ContactSchema.BusinessPhone, ContactSchema.HomePhone,
ContactSchema.OtherTelephone,
ContactSchema.CompanyMainPhone, ContactSchema.HomeFax, ContactSchema.BusinessFax, ContactSchema.OtherFax,
ContactSchema.MobilePhone, ContactSchema.CarPhone, ContactSchema.RadioPhone, ContactSchema.Pager,
ContactSchema.Isdn,
ContactSchema.Callback, ContactSchema.TtyTddPhone, ContactSchema.BusinessAddressCity,
ContactSchema.BusinessAddressCountryOrRegion,
ContactSchema.BusinessAddressPostalCode, ContactSchema.BusinessAddressState,
ContactSchema.BusinessAddressStreet,
ContactSchema.HomeAddressCity, ContactSchema.HomeAddressCountryOrRegion, ContactSchema.HomeAddressPostalCode,
ContactSchema.HomeAddressState, ContactSchema.HomeAddressStreet, ContactSchema.OtherAddressCity,
ContactSchema.OtherAddressCountryOrRegion, ContactSchema.OtherAddressPostalCode,
ContactSchema.OtherAddressState,
ContactSchema.OtherAddressStreet, ContactSchema.ImAddress1, ContactSchema.ImAddress2,
ContactSchema.ImAddress3,
ContactSchema.EmailAddress1, ContactSchema.EmailAddress2, ContactSchema.EmailAddress3,
ContactSchema.Birthday,
ContactSchema.Notes);
正如您在图片和代码中看到的那样,我没有从办公室Webservice获取数据,但是当我在webbrowser中进行API调用时,数据就在那里。那么我做错了什么?
这是webbrowser中的数据:
答案 0 :(得分:1)
以下代码:
var contactsFolder = ContactsFolder.Bind(_service, WellKnownFolderName.Contacts,
new PropertySet(BasePropertySet.IdOnly, FolderSchema.TotalCount));
您应该使用BasePropertySet.FirstClassProperties而不是BasePropertySet.IdOnly创建PropertySet。因此它将返回这些属性。请点击链接了解详情。