Vairamuthu
Vairamuthu

Reputation: 21

How to add the contact using EWS

I have 2 questions

  1. I want to add the email Contact to Exchange server.I have seen the sample code using EWS.But that code used to add the contact for user specific.How to add the contact domain specific.

  2. I want to get the domain contacts from Exchange server.I dont want all the contact i need only the today's added or modified contacts.

How can i acheive this .Can any one help me?

Regards Vairamuthu.G.S

Upvotes: 1

Views: 630

Answers (1)

Soulaiman ghanem
Soulaiman ghanem

Reputation: 39

I did not understand "contact domain specific" but I will share you my code. It may help

Adding contact

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
// you should set the credentials of the user and 
//call AutoDiscover to get the service URL before executing the code
Contact newcontact = new Contact(service);
newcontact.DisplayName = "data";
newcontact.EmailAddresses[EmailAddressKey.EmailAddress1] = new EmailAddress();
newcontact.EmailAddresses[EmailAddressKey.EmailAddress1].Address = "data";
newcontact.EmailAddresses[EmailAddressKey.EmailAddress1].Name = newcontact.DisplayName;
newcontact.FileAs = newcontact.DisplayName;
newcontact.Save();

Note that the new contact is saved in the contacts folder in the mailbox of the logging in user.

Filtering the retrieved contacts

SearchFilter filter = new SearchFilter.IsGreaterThan(ItemSchema.DateTimeCreated, DateTime.Now.AddDays(-1));
FindItemsResults<Item> contactCreatedToday = service.FindItems(WellKnownFolderName.Contacts, filter, new ItemView(int.MaxValue));
foreach (Item t in contactCreatedToday)
{
    try
    {
        Contact c = (Contact) t;
        //do processing
    }
    catch (InvalidCastException)
    {
        throw;
    }
}

Upvotes: 1

Related Questions