Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / VB

Sync Calendar Creator Export .CSV to Google Calendar

5.00/5 (1 vote)
11 Aug 2015CPOL3 min read 17K   137  
This sample program demonstrates how to use Google Calendar API v3 to delete Google Calendar events, insert Google Calendar events and update Google calendar events based on a .CSV file exported from Calendar Creator.

Introduction

If Calendar Creator is used as your master calendar, this program can be used to sync your Google Calendar to your Calendar Creator calendar. It can also be viewed as an example of how to use Google Calendar API v3.

Background

I use Calendar Creator as my master household calendar. To push the calendar to our Android phones, I would occasionally delete my entire Google Calendar and then import the Calendar Creator Export .CSV file. I could only import the file after I had done significant editing because the Calendar Creator Export .CSV file is not in the format that Google Calendar expects. This took a lot of mouse clicks and a fair amount of time. I decided to write a program to read the Calendar Creator Export .CSV file and sync my Google Calendar to its contents using the Google Calendar API v3. My program now takes 16 seconds to update the Google Calendar after only one double-click to initiate it.

Using the Code

  1. You must have a Google OAUTH 2.0 Credential of the type Client ID and the associated Client Secret to compile and use this program. You can obtain these by creating a project with the Google Developers Console. After that, complete the process in the APIs & auth section. First, create a new Client ID of type "Installed application." Then, configure the Consent screen by entering your gmail.com email address and your product name. Finally, enable the Calendar API in the APIs section.

    The first time that the program is executed on a computer, a browser window will open to request permission. A OAuth 2.0 token is saved and automatically refreshed by the .NET Calendar API v3 library.

    Edit the following two lines in Main.vb to insert your Client ID and Client Secret:

    VB.NET
    Private Const GOOGLE_CLIENT_ID As String = "YOUR CLIENT ID GOES HERE"
    Private Const GOOGLE_CLIENT_SECRET As String = "YOUR CLIENT SECRET GOES HERE"
    
  2. The Google Calendar API and associated NuGet packages are not included with the source code attached to this tip article. To add these to your project in Visual Studio, select Tools / NuGet Package Manager / Package Manager Console and enter the following command:
    Install-Package Google.Apis.Calendar.v3
    
  3. You may want to customize this program to ensure that all of the custom event categories that you use in Calendar Creator to signify All Day Events are included in the following boolean statement. This statement is found in the CalendarCreatorEventConstructor method of the clsCalendarCreatorEvent Class in Main.vb.
    VB.NET
    m_AllDay = strCategoryUpcased = "BIRTHDAYS" OrElse _
      strCategoryUpcased = "ANNIVERSARY" OrElse _
      strCategoryUpcased = "ALL DAY EVENT" OrElse _
      strCategoryUpcased.Contains("US HOLIDAYS")
    
  4. Those categories and any event that starts at 12:00AM and ends at either 11:59PM or 12:00AM are treated as an All Day Event. In Google Calendar, All Day Events appear in a separate section at the top of each day column.
    VB.NET
    If strStartTime = "0:00" AndAlso (strStopTime = "0:00" OrElse strStopTime = "23:59") Then
        m_AllDay = True
    End If
    
    If m_AllDay Then
        strStartTime = "0:00"
        strStopTime = "0:00"
    End If
    
  5. When executing this program, the commandline parameter must be the full path filename to the Calendar Creator Export .CSV file.

    Example:

    BAT
    SyncCalendarCreator.exe C:\users\YOUR_USER_NAME\Desktop\Export.csv
    

Points of Interest

  1. The following Google Calendar APIs are used in this program. Documentation for these and other Google Calendar APIs is available on the Calendar API v3 Class Documentation page.
    CalendarService.CalendarList.List
    CalendarService.Events.List
    CalendarService.EventsResource.DeleteRequest
    CalendarService.EventsResource.InsertRequest
    CalendarService.EventsResource.UpdateRequest
    
  2. If there are any events in the Google Calendar that are configured as recurring events, they are ignored by this program. The Calendar Creator Export .CSV file contains only individual day events. Any recurring events configured in Calendar Creator are output to the exported .CSV file as multiple events on their respective days.
  3. This program uses the earliest date and latest date found in the Calendar Creator Export .CSV file to determine how much of your Google Calendar is to be modified.
    VB.NET
    '
    ' Sort by date, subject, description
    '
    colCalendarCreatorEvents.Sort(AddressOf EventComparer)
    '
    ' Extract dates to be used later for Google Calendar query
    '
    dtStart = colCalendarCreatorEvents.Item(0).StartDate.Date  ' First date in .CSV file
    dtStop = DateAdd(DateInterval.Day, 1, colCalendarCreatorEvents.Item
        (colCalendarCreatorEvents.Count - 1).StartDate).Date ' Last date in .CSV file
    

History

  • 08/11/2015: Initial version
  • 08/23/2015: Use a custom credentials FileDataStore with the UserName in the filename.
  • 08/24/2015: Small change to comment in source code.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)