SearchAsync Method
Collapse the table of content
Expand the table of content

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 void SearchAsync(
	string filter,
	FilterKind filterKind,
	Object state


Type: System.String
The filter to use to search for contacts.
Type: Microsoft.Phone.UserData.FilterKind
The kind of filter to use when searching for contacts.
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.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1

Windows Phone

© 2017 Microsoft