Search code examples
c#windows-phone-8

How to access contacts in windows phone app 8.0?


I have a form to enter a phone number.

user should be able to select the contacts from his contact list by a click of a button. When the user selects a contact the numbers should appear in a text box in the form..

Can some one kindly help me code this... any kind of help is appreciated......


Solution

  • using Microsoft.Phone.UserData;

    Is what you're looking for..

    Something like :

    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());
    }
    

    The documentation on this is quite verbose : MSDN