Contacts.SearchAsync Method

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

Asynchronously searches for contacts in the user’s contact data.

Namespace:  Microsoft.Phone.UserData
Assembly:  Microsoft.Phone (in Microsoft.Phone.dll)


Public Sub SearchAsync ( _
    filter As String, _
    filterKind As FilterKind, _
    state As Object _
public void SearchAsync(
    string filter,
    FilterKind filterKind,
    Object state


  • state
    Type: System..::.Object
    A user-defined object that contains information about the operation.


If the filterKind is EmailAddress, PhoneNumber, or DisplayName, then filter should contain a string to attempt to match. The filter parameter is ignored if the filterKind is None or PinnedToStart. For more information about how the filter is used to match contacts, see Contact filtering and matching for Windows Phone 8.

The state object is stored in the ContactsSearchEventArgs class and passed to the SearchCompleted delegate when the operation is complete.

Applications that use the Contacts APIs may fail to start. This can occur for applications that are upgraded from Windows Phone OS 7.0 to Windows Phone OS 7.1. To resolve this issue, open the file WMAppManifest.xml and add the following element.

<Capability Name="ID_CAP_CONTACTS"/>


The following example assumes that you have a Windows Phone application that has a page with a button named SearchContacts. The code assumes that you have a databound list box named ContactResultsData. For the full example, including the XAML, see How to access contact data for Windows Phone 8.

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Microsoft.Phone.Controls;
using Microsoft.Phone.UserData;

namespace ContactsAndCalendarTestApp
    public partial class ContactsPage : PhoneApplicationPage
        // Constructor
        public ContactsPage()

        private void SearchContacts_Click(object sender, RoutedEventArgs e)
            ContactResultsData.DataContext = null;

            Contacts cons = new Contacts();

            cons.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(Contacts_SearchCompleted);

            cons.SearchAsync(“A”, FilterKind.DisplayName, "Contacts Test #1");

        void Contacts_SearchCompleted(object sender, ContactsSearchEventArgs e)

                //Bind the results to the list box that displays them in the UI.
                ContactResultsData.DataContext = e.Results;
            catch (System.Exception)
                //That's okay, no results.
Imports Microsoft.Phone.UserData

Partial Public Class ContactsPage
    Inherits PhoneApplicationPage

    Public Sub New()
    End Sub

    Private Sub SearchContacts_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)

        ContactResultsData.DataContext = Nothing
        Dim cons As Contacts = New Contacts()

        AddHandler cons.SearchCompleted, AddressOf Contacts_SearchCompleted

        cons.SearchAsync("A", FilterKind.DisplayName, "Contacts Test #1")
    End Sub

    Private Sub Contacts_SearchCompleted(sender As Object, e As ContactsSearchEventArgs)

            'Bind the results to the list box that displays them in the UI.
            ContactResultsData.DataContext = e.Results

        Catch ex As System.Exception

            'That's okay, no results.
        End Try
    End Sub
End Class

Version Information

Windows Phone OS

Supported in: 8.1, 8.0, 7.1


Windows Phone

See Also


Contacts Class

Microsoft.Phone.UserData Namespace

Other Resources

Contacts and Calendar for Windows Phone 8

How to access contact data for Windows Phone 8

App manifest file for Windows Phone 8