Question

I'm trying to deserialize an iCal file and then map the collection to a custom POCO. The problem is that I'm not sure where the properties are stored.

Here's the Deserialization method

public static IICalendarCollection Deserialize(String iCalUri)
{

    var wc = new WebClient();
    var result = wc.DownloadString(iCalUri);

    using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(result)))
    {
        var serializer = new iCalendarSerializer();
        var collection = (iCalendarCollection)serializer.Deserialize(memoryStream, Encoding.UTF8);
        return collection;
    }
}

Then in my service, I'm trying to map the properties to my POCO, but I can't find the properties.

var url = string.Format(GoogleICalUrl, calendarID);
var feed = iCalUtility.Deserialize(url);

foreach(var e in feed)
{
    calendarModel.title = e.WhereTheHellAreThePropertiesKept;
}

Does anyone know the right way to loop through the iCalendarCollection and get all the properties?

I checked the DDay website but it's been down all day.

Was it helpful?

Solution

After some digging, it turns out that IICalendarCollection has a nested Event collection that needs to be parsed as follows.

var url = string.Format(GoogleICalUrl, calendarID);
var feed = iCalUtility.Deserialize(url);

foreach (var ev in feed.SelectMany(e => e.Events))
{
    calendarModel.Add(new CalendarModel {description = ev.Description,
                                         title = ev.Summary});
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top