Reputation: 2170
We can get 'ONE' phone number, email address etc of a contact with this code.
Contacts ContactsObj = new Contacts();
ContactsObj.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(func);
ContactsObj.SearchAsync(String.Empty, FilterKind.None, null);
/
void func(object sender, ContactsSearchEventArgs e)
{
foreach (var result in e.Results)
{
txtBlock.Text += result.PhoneNumbers.FirstOrDefault()+ "," + result.EmailAddresses.FirstOrDefault();
}
}
But as there can be more emails/numbers stored in one contact. Is there a way to get all phone numbers, email addresses etc of a contact in a string?
Upvotes: 1
Views: 912
Reputation: 488
You can access more than 1 email Ids and Phone Numbers by using foreach. The following code worked for me.
foreach (Microsoft.Phone.UserData.ContactEmailAddress ad in result.EmailAddresses)
{
txtBlock.Text += ad.EmailAddress;
}
foreach (Microsoft.Phone.UserData.ContactPhoneNumber ph in result.PhoneNumbers)
{
txtBlock.Text += ph.PhoneNumber;
}
Upvotes: 4