Google Calendar is a scheduling service that lets you create and keep track of the events such as meetings. You can log the events on the calendar and get reminders about the upcoming ones. Google also allows you to use its calendaring service programmatically. Thus, you can manage your events using Google Calendars from within your applications. In this article, you will learn how to create, update, and delete Google Calendar programmatically in C#.
- .NET API to Create and Manipulate Google Calendar
- Create a Google Calendar in C#
- Update a Google Calendar in C#
- Delete a Google Calendar in C#
C# .NET API to Create and Manipulate Google Calendar
In order to work with the Google Calendar service, we will use Aspose.Email for .NET. It is a powerful API that provides a range of features for processing emails, working with email clients, and using Google’s collaboration services. You can either download the API’s DLL or install it from NuGet using the following command.
PM> Install-Package Aspose.Email
Before you start working, you need to create a project on the Google Developer Console, which will allow your application to communicate with Google services. To create one, you can follow this guide.
To access and manipulate Google Calendar, we need to write some code to handle the user’s information and perform authentication. For the Google user, we will first create a class named TestUser and then inherit it from GoogleUser class. The following is the complete implementation of both of the classes.
Now, we need to create a helper class that will take care of the authentication of a Google account. We will name this class as GoogleOAuthHelper. The following is the complete implementation of this class.
Create a Google Calendar in C#
Once you have done the above configuration, you can proceed to work with the Google Calendar service. The following are the steps to create and update a Google Calendar in C#.
- Get an instance of GmailClient class into an IGmailClient object using GmailClient.GetInstance(String, String) method.
- Create an instance of the Calendar class and initialize it with name, description, and other properties.
- Call IGmailClient.CreateCalendar(Calendar) method to create the Google Calendar.
- Get the returned ID of the calendar.
The following code sample shows how to create a Google Calendar in C#.
Update a Google Calendar in C#
The following are the steps to update a Google Calendar programmatically in C#.
- Get an instance of GmailClient class into an IGmailClient object using GmailClient.GetInstance(String, String) method.
- Use IGmailClient.FetchCalendar(String) method to fetch the calendar instance using its ID.
- Update the properties of the calendar and call IGmailClient.UpdateCalendar(Calendar) method to update the calendar.
The following code sample shows how to update a Google Calendar in C#.
Delete a Google Calendar in C#
You can also delete a particular calendar using Aspose.Email for .NET. The following are the steps to perform this operation.
- Get an instance of GmailClient class into an IGmailClient object using GmailClient.GetInstance(String, String) method.
- Get list of calendars using IGmailClient.ListCalendars() method.
- Loop through the list and filter the desired one.
- Delete calendar using IGmailClient.DeleteCalendar(Calendar.Id) method.
The following code sample shows how to delete a Google Calendar in C#.
Get a Free API License
You can get a free temporary license to use Aspose.Email for .NET without evaluation limitations.
Conclusion
In this article, you have learned how to create Google Calendar programmatically in C#. Moreover, you have seen how to update and delete a particular Google Calendar in C#. Besides, you can explore the documentation to read more about Aspose.Email for .NET. Also, you can ask your questions via our forum.