none
Search and Update Contact RRS feed

  • Question

  • Hi,

    I am trying to update other contact information using service account. I have following code

    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
    service.Credentials = new WebCredentials("serviceaccount@xxxxx.com", "servicepassword");

    service.HttpHeaders.Add("X-AnchorMailbox", "user1@xxxxx.com");
    service.HttpHeaders.Add("X-PreferServerAffinity", "true"); ;
    service.AutodiscoverUrl("user1@xxxxx.com", RedirectionUrlValidationCallback);

    FolderId InboxId = new FolderId(WellKnownFolderName.Contacts, "user1@xxxxx.com");
    SearchFilter.SearchFilterCollection searchFilterCollection = new SearchFilter.SearchFilterCollection(LogicalOperator.And);
    searchFilterCollection.Add(new SearchFilter.IsEqualTo(ContactSchema.GivenName, "first"));
    searchFilterCollection.Add(new SearchFilter.IsEqualTo(ContactSchema.Surname, "last"));

    FindItemsResults<Item> findResults = service.FindItems(InboxId, searchFilterCollection, new ItemView(int.MaxValue));
    foreach (Item item in findResults)
    {
    if (item is Contact)
    {
        Contact contact = item as Contact;

        contact.MiddleName = "EWS Update";
        contact.Update(ConflictResolutionMode.AutoResolve);
        Console.WriteLine(contact.GivenName + "=========" + contact.Surname + "===========" + contact.DisplayName);
    }
    }

    It throws exception at contact.Update(ConflictResolutionMode.AutoResolve). Exception message "When making a request as an account that does not have a mailbox, you must specify the mailbox primary SMTP address for any distinguished folder Ids"

    Though It updates middle name.


    Satyam MCITP, MCPD

    Tuesday, April 5, 2016 5:06 PM

All replies