In this article I will explore how to get the Appointments detail from Calendar in Windows Phone 7. I will use Appointment and Appointments class available in Microsoft.Phone.UserData of Windows Phone 7 to get the calendar data.Windows Phone 7 emulator does not contain any sample appointments. One needs to test Appointments illustration in this article in physical device.
Let's write some code.
Step 1: Create a button in the MainPage.xaml to get appointment details.
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Button x:Name="btnAppointments" Margin="20,100,0,0" Height="80" Click="btnAppointments_Click" Content="Get Appointments"></Button>
Step 2: Add Microsoft.Phone.UserData.
We will use Appointments and Appointment class of Microsoft.Phone.UserData. Appointments class allows user to get the Appointment between specified date. Appointment class contains all the data of particular appointment.
SearchAsync method searches appointment asynchronously which occur between specied start date and time and end date and time and returns the appointment between the specified period.We can also pass maximum number of appointments to return.
SearchCompleted event triggers when search of appointments completed.
Account returns kind of account and name.
Kind of a account, such as Microsoft.Phone.UserData.StorageKind.Phone or Microsoft.Phone.UserData.StorageKind.Outlook.
Name of the account such as Work Email.
Attendees returns the list of attendee of the appointment. Attendee provides Displayname and EmailAddress of the attendee.
Details provides the detail description of appointment.
EndTime provides the date and time of the appointment ends.
IsAllDayEvent returns boolean value indicating whether the appointment is all day event.
IsPrivate returns boolean value indicating whether the appointment is private.
Location returns the location of the appointment.
Organizer provides information on the organizer of the appointment. It returns Attendee object. One can get DisplayName and Email address of organizer.
StartTime provides the date and time of the appointment starts.
Status returns the AppointmentStatus object. It is used to get information how to treat the block of the appointment, such as busy or out of office.
Subject returns the subject of the appointment.
Step 3: Add btnAppointments_Click event in the codebehind of MainPage.xaml.
Add Appointments_SearchCompleted event to Appointments and then call SearchAsynch method with start date and time, end date and time and maximum number of appointment to return.
private void btnAppointments_Click(object sender, RoutedEventArgs e)
Appointments appointments = new Appointments();
appointments.SearchCompleted += new EventHandler<AppointmentsSearchEventArgs>(Appointments_SearchCompleted);
DateTime start = DateTime.Now;
DateTime end = start.AddDays(7);
int max = 10;
//Start the asynchronous search.
appointments.SearchAsync(start, end, max, "Appointments Test");
Step 4: Now we will write Appointments_SearchCompleted method to get the appointment details.
void Appointments_SearchCompleted(object sender, AppointmentsSearchEventArgs e)
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (Appointment appt in e.Results)
Account acnt = appt.Account;
foreach (Attendee attendee in appt.Attendees)
Attendee attendeeOrganizer = appt.Organizer;
AppointmentStatus appointmentStatus = appt.Status;
This ends the artilce of getting appointment details from calendar in Windows Phone 7.