0

So far I am able to insert an event in a calendar using the following code.

    Dim calService As CalendarService = calendarFunctions.getCalendarService(txtrefreshToken.Text.Trim)
    Dim calEventEntry As New Data.Event
    calEventEntry.Summary = "Invoice #123456 Due on dd/mm/yyyy"
    calEventEntry.Description = "Client: Acme Printing Ltd."
    calEventEntry.Id = "inv5670010"

    Dim eventStartDT As New Data.EventDateTime()
    eventStartDT.DateTime = DateTime.Now.AddHours(24)
    Dim eventStartEndDT As New Data.EventDateTime()
    eventStartEndDT.DateTime = DateTime.Now.AddHours(25)
    calEventEntry.Start = eventStartDT
    calEventEntry.End = eventStartEndDT
    Dim er As New EventsResource(calService)
    Dim erResp As Data.Event = er.Insert(calEventEntry, txtactiveCal.Text.Trim).Execute()

    'SO FAR SO GOOD!
    'Add email reminder to event 
    Dim remR As New EventReminder()
    remR.Method = "email"
    remR.Minutes = 10
    erResp.Reminders.Overrides.Add(remR) ' <<< ERROR: Object reference not set to an instance of an object

In the last block I am trying to add the reminder to the event (I unserstand this must be done after the event has been created?) . On the last line I get the following error:

Object reference not set to an instance of an object

Does anyone know what I'm doing wrong here?

QFDev
  • 8,668
  • 14
  • 58
  • 85

2 Answers2

0

I would suspect Overrides to be null by default so you can't add anything in there unless you initialize them.

luc
  • 3,642
  • 1
  • 18
  • 21
0

I solved this in the end by creating a List(of EventReminder) object adding the desired reminder and binding this to the Overrides property for event.reminders. Hopefully this code may be of help to others.

    Dim eventReminder As New List(Of EventReminder)()
    eventReminder.Add(New EventReminder() With { _
         .Minutes = 10, _
         .Method = "email" _
    })

    Dim de As New Data.Event.RemindersData()
    de.UseDefault = False
    de.[Overrides] = eventReminder

    calEventEntry.Reminders = de

    Dim er As New EventsResource(calService)
    Dim erResp As Data.Event = er.Insert(calEventEntry, txtactiveCal.Text.Trim).Execute()

    Response.Write("Event ID: " & erResp.Id & "<br/>")
    Response.Write("Link: <a href=""" & erResp.HtmlLink & """>" & erResp.HtmlLink & "</a><br/>")
QFDev
  • 8,668
  • 14
  • 58
  • 85