Raymund
Raymund

Reputation: 7892

Reading Google Calendar recurring events using .Net API

I am doing some sync across different calendar formats and one of the Calendar providers is Google, Other providers expose this data in an object oriented approach through their API but in Google it is exposed via Events.Recurrence as this:

"DTSTART;TZID=Pacific/Auckland:20110629T100000\r\n
DTEND;TZID=Pacific/Auckland:20110629T110000\r\n
RRULE:FREQ=DAILY;COUNT=10;INTERVAL=3\r\n
BEGIN:VTIMEZONE\r\n
TZID:Pacific/Auckland\r\n
X-LIC-LOCATION:Pacific/Auckland\r\n
BEGIN:DAYLIGHT\r\n
TZOFFSETFROM:+1200\r\n
TZOFFSETTO:+1300\r\n
TZNAME:NZDT\r\n
DTSTART:19700927T020000\r\n
RRULE:FREQ=YEARLY;BYMONTH=9;BYDAY=-1SU\r\n
END:DAYLIGHT\r\n
BEGIN:STANDARD\r\n
TZOFFSETFROM:+1300\r\n
TZOFFSETTO:+1200\r\n
TZNAME:NZST\r\n
DTSTART:19700405T030000\r\n
RRULE:FREQ=YEARLY;BYMONTH=4;BYDAY=1SU\r\n
END:STANDARD\r\n
END:VTIMEZONE"

Is there any way of parsing this to an object oriented format? i.e. a Recurrence object? All of the samples I saw online are setting those values which is easier rather than reading it. Any samples of reading and writing to it are welcome.

Upvotes: 1

Views: 1788

Answers (2)

bpiec
bpiec

Reputation: 1631

Try this library: http://icalparser.sourceforge.net/

Upvotes: 1

KristianMedK
KristianMedK

Reputation: 1841

EventEntry.Times is a collection, so you have to parse it into an ExtensionCollection object, which you can then iterate through.

foreach (Google.GData.Calendar.EventEntry ev in calFeed.Entries)
    {
        CalendarEvents ce = new CalendarEvents();

        ce.Title = ev.Title.Text;
        ExtensionCollection<When> v = ev.Times;
        ce.Date = v[0].StartTime;
        ce.Content = ev.Content.Content;
    }

Iterating wasn't necessary in my project, but i think you get the idea.

Upvotes: 2

Related Questions