How to Create Appointment in WP8 using SaveAppointmentTask?



In the last blog post, we learnt “How to Share a Media File from WP8 using the ShareMediaTask?” which 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 blog post 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 you an API named SaveAppointmentTask, which 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 which launches a dialog that allows a user to create and save 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 those you want to populate 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:

 

var saveAppointmentTask = new SaveAppointmentTask();
 
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 can not silently create an appointment as the user interaction is needed for security reason and that is defined by the Microsoft Windows Phone 8 SDK.

 

I hope that the post 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.

 

Are you on Twitter? Don’t forget to connect with me. I am also available in Facebook and Google+. Stay connected. Feel free to subscribe to my blog’s RSS feed and email newsletter to get all article updates directly delivered to your inbox.

12 comments

  1. Hi guys, i have some question for you. I'll make some application in WP8 that can generate few appoinment then insert it on calendar. Is it possible? And what method should i use? Thanks

    ReplyDelete
    Replies
    1. Thanks for fast reply in twitter, Sir :D
      Now i build application for managing activities. In the beginning, this application need input (date) from user, then application will create schedule ahead (more than one appoinment/reminder). I've heard that in WP8 there is some issue "security reason" for inserting appoinment. If it can't insert appoinment directly from this application, can I call alarm for every schedule i've created even though mobile phones are switched off?

      Delete
    2. Hi Riyan,

      Sorry for the late reply as I was busy with some other stuffs.

      Yes, you can not silently insert appointments in Windows Phone (7 or 8, whatever) without seeking permission from the user. This is because Microsoft restricts us for security reason. Not only that, you will not be able to add/edit contacts too without user's intervention.

      To answer your second query, that depends on the device manufacturer and as much as I know, none of the Windows Phone devices permit you to do so. Hope, these answers all your queries.

      Regards,
      Kunal

      Delete
  2. It can be used in WP7?? I need to make appointments using the calendar system, but I'm developing on WP7. What options do I have? thanks in advance..!

    ReplyDelete
    Replies
    1. Unfortunately this API is only available in WP8 SDK and hence you can not use it in WP7.

      Delete
  3. Can i delete the Existing appointment from the Calender?

    ReplyDelete
    Replies
    1. I am not sure but I guess, we can not. Will check it out and update you. Let me know, if you find anything by this time.

      Delete
  4. Replies
    1. Yes, you can but the only thing is, you can not do these operations silently. User can change.

      Delete
  5. I have a calendar option in my app itself. So how to add multiple events on that calendar. Please reply me as soon as possible.

    ReplyDelete
    Replies
    1. Hi Imran,

      You can not do it in bulk. You have to write code to add the events one-by-one and yes, that needs user's intervention.

      Delete
  6. Can i check if the appointment is saved successfully in calendar programatically?

    ReplyDelete


 
© 2008-2014 Kunal-Chowdhury.com | Designed by Kunal Chowdhury
Back to top