Question

I have successfully added single appointment using this code now i want to add multiple appointment pro grammatically in a single loop.for example i want to add 5 appointment at a time using loop where dates for every appointment is available in a List. Thanks in advance :)

SaveAppointmentTask saveAppointmentTask = new SaveAppointmentTask();          
saveAppointmentTask.StartTime = nearestDate;

saveAppointmentTask.EndTime = nearestDate.AddMinutes(3) ;

saveAppointmentTask.Subject = "Meet Ali"; // appointment subject

saveAppointmentTask.Location = "In Office"; // appointment location

saveAppointmentTask.Details = "Meet Ali to discuss product launch";//appointment details
saveAppointmentTask.IsAllDayEvent = false;
saveAppointmentTask.Reminder = Microsoft.Phone.Tasks.Reminder.FifteenMinutes;
saveAppointmentTask.AppointmentStatus = Microsoft.Phone.UserData.AppointmentStatus.OutOfOffice;
saveAppointmentTask.Show();
Was it helpful?

Solution

use this code as Navigated To event is all the time called when you land up in the page

private SaveAppointmentTask saveAppointmentTask;
    private List<int> listMinutes = new List<int>();
    // Constructor
    public MainPage()
    {
        InitializeComponent();

        for (int i = 0; i < 10; i++) {
            listMinutes.Add(i);
        }

    }

    int countAdded = 0;
    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {

        if (countAdded < 10)
        {

            saveAppointmentTask = new SaveAppointmentTask();
            saveAppointmentTask.StartTime = DateTime.Now.AddMinutes(listMinutes[countAdded]);

            saveAppointmentTask.EndTime = saveAppointmentTask.StartTime.Value.AddMinutes(2);

            saveAppointmentTask.Subject = "Meet Ali"; // appointment subject

            saveAppointmentTask.Location = "In Office"; // appointment location

            saveAppointmentTask.Details = "Meet Ali to discuss product launch";//appointment details
            saveAppointmentTask.IsAllDayEvent = false;
            saveAppointmentTask.Reminder = Microsoft.Phone.Tasks.Reminder.FifteenMinutes;
            saveAppointmentTask.AppointmentStatus = Microsoft.Phone.UserData.AppointmentStatus.OutOfOffice;
            countAdded++;
            saveAppointmentTask.Show();
        }
        else { 
            // do not add anything
        }


    }

save i that is the count in some application state or a tokes so that you can know if you have added the events :) Appplication.Current.Resources.Add("token", "number added")

Thanks

OTHER TIPS

You cannot automatically save all appointments. You would have to launch the task in each iteration, and user interaction would be nedded in each.

A possible option is to use the Live Connect API. That would allow you to programatically create apointments in user's Live calendar:

Interacting with calendars (Live Connect API)

This way you don't interact with the phone calendar, but the users's Live calendar, which can be synchronized in the phone. Of course, the user will need to authenticate.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top