Appointments.SearchAsync Method (DateTime, DateTime, Account, Object)

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

Asynchronously searches for appointments that occur between the specified start date and time and end date and time, from the specified data source.

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


Public Sub SearchAsync ( _
    startTimeInclusive As DateTime, _
    endTimeInclusive As DateTime, _
    account As Account, _
    state As Object _
public void SearchAsync(
    DateTime startTimeInclusive,
    DateTime endTimeInclusive,
    Account account,
    Object state


  • startTimeInclusive
    Type: System..::.DateTime
    The start date and time to use to search for appointments.
  • endTimeInclusive
    Type: System..::.DateTime
    The end date and time to use to search for appointments.
  • state
    Type: System..::.Object
    A user-defined object that contains information about the operation.


The maximum number of appointments that are returned is stored in DefaultMaximumItems.

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

Applications that use the Calendar 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_APPOINTMENTS"/>


The following example assumes that you have a Windows Phone application that has a page with a button named SearchAppointments. The code assumes that you have a databound list box named AppointmentResultsData. In this example, you search for all appointments in the next seven days. For the full example, including the XAML, see How to access calendar 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 AppointmentsPage : PhoneApplicationPage
        public AppointmentsPage()

        private void SearchAppointments_Click(object sender, RoutedEventArgs e)
            AppointmentResultsData.DataContext = null;
            Appointments appts = new Appointments();

            appts.SearchCompleted += new EventHandler<AppointmentsSearchEventArgs>(Appointments_SearchCompleted);

            DateTime start = new DateTime();
            start = DateTime.Now;

            DateTime end = new DateTime();
            end = start.AddDays(7);

            foreach (Account acct in (new Appointments()).Accounts)
                appts.SearchAsync(start, end, acct, "Appointments Test " + acct.Kind.ToString());

        void Appointments_SearchCompleted(object sender, AppointmentsSearchEventArgs e)

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

Partial Public Class AppointmentsPage
    Inherits PhoneApplicationPage

    Public Sub New()
    End Sub

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

        AppointmentResultsData.DataContext = Nothing

        Dim appts As Appointments = new Appointments()

        AddHandler appts.SearchCompleted, AddressOf Appointments_SearchCompleted

        Dim start As DateTime = DateTime.Now
        Dim endTime As DateTime = start.AddDays(7)

        For Each acct As Account In (new Appointments()).Accounts

            appts.SearchAsync(start, endTime, acct, "Appointments Test " + acct.Kind.ToString())
    End Sub

    Private Sub Appointments_SearchCompleted(sender As Object, e As AppointmentsSearchEventArgs)


            'Bind the results to the list box that displays them in the UI.
            AppointmentResultsData.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


Appointments Class

SearchAsync Overload

Microsoft.Phone.UserData Namespace

Other Resources

Contacts and Calendar for Windows Phone 8

How to access calendar data for Windows Phone 8

App manifest file for Windows Phone 8