Click here to Skip to main content
15,886,519 members
Articles / Programming Languages / Visual Basic
Tip/Trick

Sync Calendar Creator Export .CSV to Google Calendar

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
11 Aug 2015CPOL3 min read 16.4K   135   2   3
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)


Written By
Retired
United States United States
I’m retired. When I started my career, programming projects consisted of plugging wires into plug boards to create punch card processing applications to be run on electrical accounting machine like the IBM 402, 407, 085, 088, 514, 519, etc. From there, I moved to writing SPS and Autocoder applications on an IBM 1401 with 4K of memory eventually upgraded to 16K of memory. After many years of migrating my skills to various languages on various hardware platforms, I became an Information Technology Director where I didn’t need to program anymore. So, starting in 1996, I volunteered my time with a local community cable television organization and built some applications to help them run their operations. Originally in Clipper Summer 1987 and later Clipper 5.2, I migrated and enhanced those applications to VB .NET 2003 in 2003. I retired from my full-time job in 2010. Since then, I have continued to support the local community cable tv organization's applications. In 2013, I migrated the VB .NET 2003 Solution to VB .NET 2012 so that it can run on 64-bit computers and interact with Microsoft Office 2010. The upgrade went smoothly. In mid 2013, I developed a VB .NET 2012 application for them to download election results data from the Secretary of State's web site, format the results and send them to a VizRT character generator for on-air display.

Comments and Discussions

 
QuestionTransferring Calendar Creator events to a Google Calendar Pin
Member 138951322-Jul-18 3:18
Member 138951322-Jul-18 3:18 
Questionredirect_uri Pin
paraFLU27-Aug-15 3:36
paraFLU27-Aug-15 3:36 
AnswerRe: redirect_uri Pin
Mike Meinz27-Aug-15 4:18
Mike Meinz27-Aug-15 4:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.