Skip to content

Instantly share code, notes, and snippets.

@chakkaradeep
Created August 11, 2014 06:08
Show Gist options
  • Save chakkaradeep/24d4182e7771eef9eaef to your computer and use it in GitHub Desktop.
Save chakkaradeep/24d4182e7771eef9eaef to your computer and use it in GitHub Desktop.
Office 365 API Contacts - Read Contacts
public static async Task<ObservableCollection<MyContact>> GetContacts()
{
ObservableCollection<MyContact> myContactList = new ObservableCollection<MyContact>();
//query contacts
var contactsResults = await _exchangeClient.Me.Contacts.OrderBy(c=>c.DisplayName).ExecuteAsync();
//fetches the first 50 contacts
//default page count is 50
var contacts = contactsResults.CurrentPage.ToList();
//enumerate and build your contact object
foreach (var contact in contacts )
{
MyContact myContact = new MyContact();
myContact.Id = contact.Id;
myContact.Name = String.Format("{0} {1}", contact.GivenName, contact.Surname);
myContact.Email = contact.EmailAddress1;
myContact.Picture = await GetContactImage(contact.Id);
myContactList.Add(myContact);
}
return myContactList;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment