user765864
user765864

Reputation: 137

How to read contact in windows phone 7 programatically using silverlight and c#?

How to read contact in windows phone 7 programatically using silverlight and c#?

Upvotes: 1

Views: 501

Answers (2)

Rejinderi
Rejinderi

Reputation: 11844

If you are on windows phone 7.0 you can only read in one contact at a time. using either the EmailAddressChooserTask or PhoneNumberChooserTask like so, you can do the same with EmailAddressChooserTask:

private PhoneNumberChooseTask myPhoneChooserTask;

public MainPage()
{
   InitializeComponent();
   myPhoneChooserTask = new PhoneNumberChooseTask ();
   myPhoneChooserTask.Completed += (o, e) => 
   {
      if (e.TaskResult == TaskResult.OK)
         //Here means the phone is chosen successfully. you can access the phone number with e.PhoneNumber
      else
         //Here means the phone is not chosen
   }
   myPhoneChooserTask.Show(); //Show contact list for choosing
}

However, with the windows OS 7.1 you can read in all contacts by using the contacts search with an empty string like so.. taken from http://msdn.microsoft.com/en-us/library/hh286416(v=vs.92).aspx

private void ButtonContacts_Click(object sender, RoutedEventArgs e)
{
    Contacts cons = new Contacts();

    //Identify the method that runs after the asynchronous search completes.
    cons.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(Contacts_SearchCompleted);

    //Start the asynchronous search.
    cons.SearchAsync(String.Empty, FilterKind.None, "Contacts Test #1");
}

void Contacts_SearchCompleted(object sender, ContactsSearchEventArgs e)
{
    //Do something with the results.
    MessageBox.Show(e.Results.Count().ToString());
}

Good luck!

Upvotes: 0

Oliver Weichhold
Oliver Weichhold

Reputation: 10296

Right now you only get access to one contact at a time through the EmailAddressChooserTask API. There's no way to read the entire contact list.

Upvotes: 2

Related Questions