2014-06-15 33 views
0

到目前爲止,我可以使用以下代碼在日曆中插入事件。Google Calender Vr3 - 如何向活動添加提醒?

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 

在最後一塊我想提醒添加到事件(我unserstand這必須在創建活動結束後做什麼?)。在最後一行我得到以下錯誤:

Object reference not set to an instance of an object 

有沒有人知道我在做什麼錯在這裏?

回答

0

我最終解決了這個問題,創建一個List(of EventReminder)對象添加所需的提醒,並將其綁定到Overrides屬性event.reminders。希望這個代碼可能對其他人有幫助。

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/>") 
0

我會懷疑覆蓋默認爲空,所以你不能在那裏添加任何東西,除非你初始化它們。