Quickstart: Selecting user contacts Windows Phone Store app using C++, C#, or Visual Basic

[This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation]

Windows Phone provides methods for finding and retrieving contacts on the device. This topic will show you how to use these APIs. This feature is for apps that only want to read contact information from the device. If you want to create a contact store on the device for your app, see Quickstart: Managing app contact stores.

Prerequisites

  • We recommend that you be familiar with Microsoft Visual Studio and its associated templates.
  • We recommend that you be familiar with C# development.

Finding contacts

The method FindContactsAsync has two overloads. The no argument version of this method returns all contacts on the device. The other version takes a string argument that the system uses as search text, returning contacts for which the string matches the name, email address, or phone number of a contact.

public async void FindContacts(string searchText)
{
    ContactStore contactStore = await ContactManager.RequestStoreAsync();

    IReadOnlyList<Contact> contacts = null;

    if(String.IsNullOrEmpty(searchText))
    { 
        // Find all contacts
        contacts = await contactStore.FindContactsAsync();
    }
    else
    {
        // Find contacts based on a search string
        contacts = await contactStore.FindContactsAsync(searchText);
    }

    MyContactListBox.ItemsSource = contacts;
}

Retrieving contacts

Retrieve a contact by calling GetContactAsync and passing in the local ID of the contact.

ContactStore contactStore = await ContactManager.RequestStoreAsync();
Contact contact = await contactStore.GetContactAsync(id);

Summary and next steps

Now you have a basic understanding of how to find and retrieve contacts on Windows Phone.