Add, Delete, Update or Move Appointments in Google Calendars using .NET

This technical tip explains how developers can use Gmail Calendars to add, retrieve delete, move or update Appointments in their own applications using Aspose.Email. Aspose.Email provides features for working with Appointments in Google calendars. Some important tasks such as adding Appointments, Retrieving list of appointments, retrieving particular appointment, updating an appointment, moving appointment from one calendar to another and deleting appointment can be performed using Google calendar. For Code Samples and other details please visit the given link.
//your code here...Adding an appointment //Following code sample demonstrates the feature of adding an appointment in a calendar. //get access token GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret"); string accessToken = GoogleOAuthHelper.GetAccessToken(User2); //Get IGmailclient using (IGmailClient client = Aspose.Email.Google.GmailClient.GetInstance(accessToken)) { //Create local calendar Calendar calendar1 = new Calendar( "summary - " + Guid.NewGuid().ToString(), null, null, "Europe/Kiev"); //Insert calendar and get id of inserted calendar string id = client.CreateCalendar(calendar1); //Get back calendar using an id Calendar cal1 = client.FetchCalendar(id); string calendarId1 = cal1.Id; try { //Retrieve list of appointments from the first calendar Appointment[] appointments = client.ListAppointments(calendarId1); //It shall be zero if (appointments.Length > 0) { Console.WriteLine("Wrong number of appointments"); return; } //Get current time and Calculate time after an hour from now DateTime startDate = DateTime.Now; DateTime endDate = startDate.AddHours(1); //Initialize a mail address collection and set attendees mail address MailAddressCollection attendees = new MailAddressCollection(); attendees.Add("User1.EMail@domain.com"); attendees.Add("User3.EMail@domain.com"); //create an appointment with above attendees Appointment app1 = new Appointment( "Location - " + Guid.NewGuid().ToString(), startDate, endDate, User2.EMail, attendees); //Set appointment summary, description, start/end time zone app1.Summary = "Summary - " + Guid.NewGuid().ToString(); app1.Description = "Description - " + Guid.NewGuid().ToString(); app1.StartTimeZone = "Europe/Kiev"; app1.EndTimeZone = "Europe/Kiev"; //Insert appointment in the first calendar inserted above and get back inserted appointment Appointment app2 = client.CreateAppointment(calendarId1, app1); //Retrieve appointment using unique id Appointment app3 = client.FetchAppointment(calendarId1, app2.UniqueId); } catch (Exception ex) { Console.WriteLine(ex.Message); } } //Retrieve and update appointment static void UpdateAppointment(string calendarId, string AppointmentUniqueId) { //get access token GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret"); string accessToken = GoogleOAuthHelper.GetAccessToken(User2); //Get IGmailclient using (IGmailClient client = Aspose.Email.Google.GmailClient.GetInstance(accessToken)) { //Retrieve Appointment Appointment app3 = client.FetchAppointment(calendarId, AppointmentUniqueId); //Change the appointment information app3.Summary = "New Summary - " + Guid.NewGuid().ToString(); app3.Description = "New Description - " + Guid.NewGuid().ToString(); app3.Location = "New Location - " + Guid.NewGuid().ToString(); app3.Flags = AppointmentFlags.AllDayEvent; app3.StartDate = DateTime.Now.AddHours(2); app3.EndDate = app3.StartDate.AddHours(1); app3.StartTimeZone = "Europe/Kiev"; app3.EndTimeZone = "Europe/Kiev"; //Update the appointment and get back updated appointment Appointment app4 = client.UpdateAppointment(calendarId, app3); } } //Move and Delete appointment static void MoveDeleteAppointment(string SourceCalendarId, string DestinationCalendarId, string TargetAppUniqueId) { //get access token GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret"); string accessToken = GoogleOAuthHelper.GetAccessToken(User2); //Get IGmailclient using (IGmailClient client = Aspose.Email.Google.GmailClient.GetInstance(accessToken)) { //Retrieve the list of appointments in the destination calendar before moving the appointment Appointment[] appointments = client.ListAppointments(DestinationCalendarId); Console.WriteLine("Before moving count = " + appointments.Length); Appointment Movedapp = client.MoveAppointment(SourceCalendarId, DestinationCalendarId, TargetAppUniqueId); //Retrieve the list of appointments in the destination calendar after moving the appointment appointments = client.ListAppointments(DestinationCalendarId); Console.WriteLine("After moving count = " + appointments.Length); //Delete particular appointment from a calendar using unique id client.DeleteAppointment(DestinationCalendarId, Movedapp.UniqueId); //Retrieve the list of appointments. It should be one less than the earlier appointments in the destination calendar appointments = client.ListAppointments(DestinationCalendarId); Console.WriteLine("After deleting count = " + appointments.Length); } } ///Import appointment and retrieve instances //get access token GoogleTestUser User2 = new GoogleTestUser("user", "email address", "password", "clientId", "client secret"); string accessToken = GoogleOAuthHelper.GetAccessToken(User2); //Get IGmailClient using (IGmailClient client = Aspose.Email.Google.GmailClient.GetInstance(accessToken)) { //Initialize calendar object Calendar calendar1 = new Calendar("summary - " + Guid.NewGuid().ToString(),null,null,"Europe/Kiev"); //Insert calendar and get back id of inserted calendar string id = client.CreateCalendar(calendar1); //Fetch same calendar using id Calendar cal1 = client.FetchCalendar(id); string calendarId1 = cal1.Id; try { //Get list of appointments from the calendar. it should be zero. Appointment[] appointments = client.ListAppointments(calendarId1); if (appointments.Length != 0) { Console.WriteLine("Wrong number of appointments."); } //Get current time as appointment start time and add an hour to calculate appointment fisnih time DateTime startDate = DateTime.Now; DateTime endDate = startDate.AddHours(1); //Initialize attendees list MailAddressCollection attendees = new MailAddressCollection(); attendees.Add("user1@domain.com"); attendees.Add("user2@domain.com"); //Create an appointment Appointment app1 = new Appointment("Location - " + Guid.NewGuid().ToString(),startDate,endDate,server.User2.EMail,attendees); app1.Summary = "Summary - " + Guid.NewGuid().ToString(); app1.Description = "Description - " + Guid.NewGuid().ToString(); app1.StartTimeZone = "Europe/Kiev"; app1.EndTimeZone = "Europe/Kiev"; //Insert appointment in the calendar and get back same appointment incase of successful insertion Appointment app2 = client.CreateAppointment(calendarId1, app1); //import the appointment from calendar 1 Appointment app3 = client.ImportAppointment(calendarId1, app2); //Get list of appointment instances in calendar using appointment unique id Appointment[] instances = client.ListAppointmentInstances(calendarId1, app2.UniqueId); //get list of appointments. It should be one appointments = client.ListAppointments(calendarId1); if (appointments.Length != 1) { Console.WriteLine("Wrong number of appointments"); return; } //Delete appointment from calendar client.DeleteAppointment(calendarId1, app2.UniqueId); //Get list of appointments from the calendar. It should be zero now. appointments = client.ListAppointments(calendarId1); if (appointments.Length != 0) { Console.WriteLine("Wrong number of appointments"); return; } } finally { //Delete calendar client.DeleteCalendar(cal1.Id); } }

Url: http://www.aspose.com/.net/email-component.aspx

Language: C# | User: Sheraz Khan | Created: Mar 5, 2014 | Tags: Appointments in Google calendars adding an appointment in calendar Retrieve list off appointments Retrieve particular appointment Update an appointment Move appointment from one calendar to another Use Google calendar