Back to Devexpress

How to: Modify Components of the Exported iCal Structure

windowsforms-7521-controls-and-libraries-scheduler-examples-data-exchange-how-to-modify-components-of-the-exported-ical-structure.md

latest4.5 KB
Original Source

How to: Modify Components of the Exported iCal Structure

  • Nov 13, 2018
  • 2 minutes to read

The following example illustrates how you can change the default METHOD value (currently set to PUBLISH) of the VCalendar component, located in iCalendar file, as shown below:

BEGIN:VCALENDAR

PRODID:-//ACME/DesktopCalendar//EN

METHOD:PUBLISH

The RFC 2446 specifies different methods that are defined for the “VEVENT” calendar component (e.g. REQUEST that makes a request for an event, CANCEL that cancels one or more instances of an existing event and others).

To modify the method’s value, use the calendar structure constructed by the iCalendarExporter and available via handling the iCalendarImporter.CalendarStructureCreated event.

csharp
using DevExpress.XtraScheduler.iCalendar;
using DevExpress.XtraScheduler.iCalendar.Components;
// ...
    iCalendarExporter exporter = new iCalendarExporter(schedulerStorage1, aptCollection);
    exporter.CalendarStructureCreated += 
        new iCalendarStructureCreatedEventHandler(exporter_CalendarStructureCreated);
void exporter_CalendarStructureCreated(object sender, iCalendarStructureCreatedEventArgs e)
        {
            iCalendarComponent cal = e.Calendars[0];
            ((StringPropertyBase)(cal.Method)).Value = "REQUEST";
        }
vb
Imports DevExpress.XtraScheduler.iCalendar
Imports DevExpress.XtraScheduler.iCalendar.Components
' ...
    Private exporter As iCalendarExporter = New iCalendarExporter(schedulerStorage1, aptCollection)
    AddHandler exporter.CalendarStructureCreated, AddressOf exporter_CalendarStructureCreated

Private Sub exporter_CalendarStructureCreated(ByVal sender As Object, _
        ByVal e As iCalendarStructureCreatedEventArgs)
            Dim cal As iCalendarComponent = e.Calendars(0)
            CType(cal.Method, StringPropertyBase).Value = "REQUEST"
End Sub

This example illustrates the use of the AppointmentExporter.AppointmentExported event to add a custom property to the VEVENT component of the iCalendar object. The RFC 2446 defines the ORGANIZER property of an event, which specifies the calendar user who initiates a scheduling exchange, e.g. the one who proposes a group meeting. To add this property to an event exported to iCal format, the following code can be used:

csharp
using DevExpress.XtraScheduler.iCalendar;
using DevExpress.XtraScheduler.iCalendar.Components;
using DevExpress.XtraScheduler.iCalendar.Native;
// ...
    iCalendarExporter exporter = new iCalendarExporter(schedulerStorage);
    exporter.AppointmentExported += new AppointmentExportedEventHandler(exporter_AppointmentExported);

    void exporter_AppointmentExported(object sender, AppointmentExportedEventArgs e) 
    {
        iCalendarAppointmentExportedEventArgs args = (iCalendarAppointmentExportedEventArgs)e;
        iContentLineParameters parameters = new iContentLineParameters();
        iContentLineParam param1 = new iContentLineParam();
        parameters.Add(param1);
        CustomProperty property = new CustomProperty("ORGANIZER", parameters, 
            "MAILTO:[email protected]");
        args.VEvent.CustomProperties.Add(property);
    }
vb
Imports DevExpress.XtraScheduler.iCalendar
Imports DevExpress.XtraScheduler.iCalendar.Components
Imports DevExpress.XtraScheduler.iCalendar.Native
' ...
    Private exporter As iCalendarExporter = New iCalendarExporter(schedulerStorage)
    AddHandler exporter.AppointmentExported, AddressOf exporter_AppointmentExported

    Private Sub exporter_AppointmentExported(ByVal sender As Object, _
        ByVal e As AppointmentExportedEventArgs)
        Dim args As iCalendarAppointmentExportedEventArgs = _
            CType(e, iCalendarAppointmentExportedEventArgs)
        Dim parameters As iContentLineParameters = New iContentLineParameters()
        Dim param1 As iContentLineParam = New iContentLineParam()
        parameters.Add(param1)
        Dim [property] As CustomProperty = New CustomProperty("ORGANIZER", _
            parameters, "MAILTO:[email protected]")
        args.VEvent.CustomProperties.Add([property])
    End Sub