如何在Exchange Web Api中更新联系人项目

问题描述:

我尝试使用空字符串更新EWS中的联系人属性,但失败.我不知道为什么.

I try to update a contact property in EWS with an empty string but it fails. I have no idea why.

 // works fine
 contact.Company = "SomeCompany";
 contact.Update(ConflictResolutionMode.AlwaysOverwrite);

 // failed in Update with a service response exception
 contact.Company = "";
 contact.Update(ConflictResolutionMode.AlwaysOverwrite);

我尝试使用null和string.Empty,但效果相同. 我究竟做错了什么?

I try null and string.Empty but its the same effect. What am I doing wrong?

您确定

Are you sure there is a Company property on the Contact type? I only see a CompanyName property which can be updated in the following way without any problems (at least when I try it):

var service = GetService();
var view = new ItemView(1);
var searchFilter = new SearchFilter.IsEqualTo(ContactSchema.EmailAddress1, "test@domain.dk");
var contacts = service.FindItems(WellKnownFolderName.Contacts, searchFilter, view);

var contact = contacts.ElementAt(0) as Contact;

// Works fine.
contact.CompanyName = "SomeCompany";
contact.Update(ConflictResolutionMode.AlwaysOverwrite);

// Works fine as well.
contact.CompanyName = "";
contact.Update(ConflictResolutionMode.AlwaysOverwrite);