Accessing Raw Calendar and Business Card Data

In addition, to high-level interfaces, the IT Hit Collab library provides low-level interfaces for accessing components, properties, property parameters and their values.

To access properties, the IComponent interface provides Properties member. Properties is a dictionary, where all properties are grouped by property name. Each property is represented by IRawProperty interface which has a list of parameters and a raw value. Each parameter, in turn, can contain a list of values.

To access components, the IComponent interface provides Components member, which is a dictionary with all components being grouped by component name. Only calendars can have internal components, the Components dictionary is always empty for card.

Enumerating Properties, their Parameters and Values

Below is an example of enumerating all properties, their values and all parameters of each property for VEVENT component:

string strCal = File.ReadAllText("C:\\event.ics");
IEnumerable<IComponent> compList = new vFormatter().Deserialize(strCal); // read iCalendar(s) or vCard(s)
IComponent compCal = compList.FirstOrDefault();
IComponent evt = compCal.Components["VEVENT"].FirstOrDefault();

foreach (KeyValuePair<string, IList<IRawProperty>> keyValue in evt.Properties)
{
    Console.WriteLine("\nProperty: " + keyValue.Key);
    foreach (IRawProperty prop in keyValue.Value)
    {
        Console.WriteLine(" Raw Value: " + prop.RawValue);
        foreach (var param in prop.Parameters)
        {
            Console.WriteLine(" Parameter: " + param.Name + ": " + string.Join(",", param.Values));
        }
    }
}

Output:

Property: UID
  Raw Value: 59E6D26F-AD9A-4B1C-A070-275E2331A944

Property: DTSTAMP
  Raw Value: 20170114T025637Z

Property: SUMMARY
  Raw Value: Meeting

Property: DTSTART
  Raw Value: 20170420T094000
  Parameter: TZID: America/Toronto

Property: DTEND
  Raw Value: 20170420T101000
  Parameter: TZID: America/Toronto

Property: COMMENT
  Raw Value: Bring project documentation
  Raw Value: Define project scope

Adding a Custom Property

To create a new custom property use the CreateRawProperty method, to add it to the list use IComponent.AddProperty method. To add a new parameter to the list use the ParameterList.Add method.

IRawProperty customProp = evt.CreateRawProperty();
customProp.RawValue = "PropVal";
customProp.Parameters.Add(newParameter("PARAM1", "VAL1"));
customProp.Parameters.Add(newParameter("PARAM2", "VAL2"));
comp.AddProperty("X-PROP1", customProp);

Deleting a Custom Property

To delete a property remove it from the Properties dictionary calling Remove method:

evt.Properties.Remove("X-PROP1");



 

 

Next Article:

Serialization and Deserialization of Calendars and Business Cards