EWS:如何查找ContactGroup的ItemId

时间:2017-07-26 19:44:39

标签: exchangewebservices

我目前正在使用Exchange Web服务(EWS)代表我冒充的用户创建ContactGroup ...

一切都很好,这里是代码:

var email = "frank@mydomain.com";
var accountPassword = "myPassword";
var emailAccountToImpersonify = "steve@mydomain.com";

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
service.Credentials = new NetworkCredential(email, accountPassword, "mydomain.com");
service.AutodiscoverUrl(email, RedirectionUrlValidationCallback);

// Make sure the account [frank@mydomain.com] is a member of the ApplicationImpersonation admin role.
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, emailAccountToImpersonify);

// Create a new ContactGroup on behalf of [steve@mydomain.com]
ContactGroup myContactGroup = new ContactGroup(service);
myContactGroup.DisplayName = "Gazou";
myContactGroup.Members.Add(new GroupMember("user1@contoso.com"));
myContactGroup.Members.Add(new GroupMember("user2@contoso.com"));
myContactGroup.Members.Add(new GroupMember("user3@contoso.com"));
myContactGroup.Save();

在创建ContactGroup Gazou 之前我想做的是:

  • 验证ContactGroup Gazou 是否已存在(<或li>)。
  • 如果是,则删除它以便再次创建。

类似的东西:

ContactGroup existingContactGroup = ContactGroup.Bind(service, **ItemId**);
if (existingContactGroup != null)
{
    existingContactGroup.Delete(DeleteMode.HardDelete);
}
else
{
    // Create a new ContactGroup on behalf of [steve@mydomain.com]
    ContactGroup myContactGroup = new ContactGroup(service);
    myContactGroup.DisplayName = "Gazou";
    myContactGroup.Members.Add(new GroupMember("user1@contoso.com"));
    myContactGroup.Members.Add(new GroupMember("user2@contoso.com"));
    myContactGroup.Members.Add(new GroupMember("user3@contoso.com"));
    myContactGroup.Save();
}

但我似乎无法知道 如何找到ContactGroup的ItemId。 我所知道的ContactGroupDisplayName Gazou

1 个答案:

答案 0 :(得分:0)

您只需要在显示名称上搜索存储组的联系人文件夹,例如

        SearchFilter sfSearch = new SearchFilter.IsEqualTo(ContactGroupSchema.DisplayName, "NameOfGroup");
        FindItemsResults<Item> findCgResults = service.FindItems(WellKnownFolderName.Contacts, sfSearch, new ItemView(1));

应该这样做