How to Create Appointment in WP8 Using SaveAppointmentTask

In the last article, we learned "How to Share a Media File from WP8 using the ShareMediaTask?" that was a launcher available in Windows Phone 8 SDK. Similarly there are few more launchers available in the SDK by which you can launch WP8 specific applications programmatically.

Today in this article we will learn how to create an appointment in Windows Phone 8 using the API named "SaveAppointmentTask". Continue reading for details.

Implementation Steps

Windows Phone 8 SDK provides an API named SaveAppointmentTask, that helps you to create an appointment programmatically from your Windows Phone 8 application. The said class is present in the "Microsoft.Phone.Tasks" namespace. SaveAppointmentTask is actually a launcher that launches a dialog that allows a user to create and save an appointment with predefined values.

To begin with the implementation steps, first create an instance of the SaveAppointmentTask present under the namespace named "Microsoft.Phone.Tasks" and then fill up the fields to be populated from your application itself. After that, call the Show() method of the SaveAppointmentTask to launch the phone application. Here is the sample code for your reference:

saveAppointmentTask.StartTime = DateTime.Now.AddHours(1);
saveAppointmentTask.EndTime = DateTime.Now.AddHours(2);
saveAppointmentTask.Subject = "Save Appointment Task Demo";
saveAppointmentTask.Location = "www.kunal-chowdhury.com";
saveAppointmentTask.Details = "Demo uses of SaveAppointmentTask to the WP8Devs";
saveAppointmentTask.IsAllDayEvent = false;
saveAppointmentTask.Reminder = Reminder.FifteenMinutes;
saveAppointmentTask.AppointmentStatus = Microsoft.Phone.UserData.AppointmentStatus.Busy;
 
saveAppointmentTask.Show();


Once you call the Show() method, it will open the Appointment client in the screen with the predefined values and ask the user to verify/modify them. Clicking the save button will then actually save the appointment to the user's phone calendar.

Here is the meta data of the "SaveAppointmentTask" class:

namespace Microsoft.Phone.Tasks

{

    public sealed class SaveAppointmentTask

    {

        public DateTime? StartTime { get; set; }

        public DateTime? EndTime { get; set; }

        public bool IsAllDayEvent { get; set; }

        public string Subject { get; set; }

        public string Location { get; set; }

        public string Details { get; set; }

        public Reminder Reminder { get; set; }

        public AppointmentStatus AppointmentStatus { get; set; }

 

        public void Show();

    }

}

Keep in mind that, you cannot silently create an appointment since the user interaction is needed for security purposes and that is defined by the Microsoft Windows Phone 8 SDK.

I hope this article was helpful and helped you to integrate the appointment creation task in your phone programmatically from your application. Let me know, if you have further queries on this. I will try to answer you as soon as I can.


Similar Articles