In v2010 vol 2, we are adding the ability to export custom VEVENT properties, when exporting to iCalendar.
Let’s see how it works.
We have a simple Appointments table:
with the standard fields that the Scheduler can work with: Start and End times, Subject, Location etc… We’ll map the ReminderData field to ReminderInfo to store the reminder data.
The RecipientsData field we intend to use for a list of email addresses. A simple scenario is a list of attendees to be notified of a meeting. We’ll map it using the CustomFieldMappings like so:
this.schedulerStorage1.Appointments.CustomFieldMappings.Add(
new AppointmentCustomFieldMapping(
"RecipientsData",
"RecipientsData",
FieldValueType.String));
Custom fields, once mapped, can be accessed directly from the Appointment object. The following InitAppointmentDisplayText demonstrates this.
private const string RecipientsDataColumn = "RecipientsData";
private void schedulerControl1_InitAppointmentDisplayText(
object sender, AppointmentDisplayTextEventArgs e) {
string attendees = Convert.ToString(e.Appointment.CustomFields[RecipientsDataColumn]);
e.Description = string.Format("{0}
Required Attendees: {1}",
e.Description,
attendees);
}
Exporting to iCalendar (.ics)
Exporting our Appointments to .ics format is done using the Storage.ExportToICalendar method.
void ExportAppointments(Stream stream) {
schedulerControl1.Storage.ExportToICalendar(stream);
}
the exported .ics file:
BEGIN:VEVENT
DTSTAMP:20100824T170910Z
DTSTART:20100920T090000Z
DTEND:20100920T103000Z
DESCRIPTION:User stories estimating and determining their priority
LOCATION:Conference Hall
SUMMARY:Release planning
UID:6f990cad-182f-4b33-be1f-de10d8d29649
BEGIN:VALARM
TRIGGER:-PT1H
ACTION:DISPLAY
END:VALARM
X-MICROSOFT-CDO-BUSYSTATUS:FREE
X-DEVEXPRESS-STATUS:FREE
X-DEVEXPRESS-LABEL:2
X-DEVEXPRESS-CUSTOMFIELD-RECIPIENTSDATA:projectmanager@company.com\;teamlea
der@company.com
END:VEVENT
Notice that in addition to all the standard VEVENT properties, there are a couple X-DEVEXPRESS prefixed ones. The ExportToICalendar does not lose any information when exporting and preserves them using a custom prefixed property, per iCalendar specifications. This is also done for custom appointment fields:
X-DEVEXPRESS-CUSTOMFIELD-RECIPIENTSDATA:projectmanager@company.com\;teamleader@company.com
Controlling the export
Our RecipientsData was intended to track the list of Attendees, which has a corresponding VEVENT property ATTENDEE. The ExportToICalendar did it’s job of exporting and preserving the appointment information but it does not know that RecipientsData is to be translated to ATTENDEE.
To fix, this we can now use a new iCalendarExporter where we can subscribe to the exporting process and add the needed VEVENT attributes.
using DevExpress.XtraScheduler.iCalendar.Components;
void ExportAppointments(Stream stream) {
iCalendarExporter exporter = new iCalendarExporter(schedulerStorage1);
exporter.AppointmentExporting += exporter_AppointmentExporting;
exporter.Export(stream);
}
void exporter_AppointmentExporting(object sender, AppointmentExportingEventArgs e) {
string s = Convert.ToString(e.Appointment.CustomFields[RecipientsDataColumn]);
string[] attendeees = s.Split(';');
iCalendarAppointmentExportingEventArgs args = e as iCalendarAppointmentExportingEventArgs;
int count = addresses.Length;
for (int i = 0; i < count; i++) {
AddEventAttendee(args.VEvent, addresses[i]);
}
}
void AddEventAttendee(VEvent ev, string address) {
TextProperty p = new TextProperty("ATTENDEE", string.Format("mailto:{0}", address));
p.AddParameter("CN", address);
p.AddParameter("RSVP", "TRUE");
ev.CustomProperties.Add(p);
}
the exported .ics file will now have the desired ATTENDEE:
BEGIN:VEVENT
//<skipped>
X-DEVEXPRESS-CUSTOMFIELD-RECIPIENTSDATA:projectmanager@company.com\;teamlea
der@company.com
ATTENDEE;CN=projectmanager@company.com;RSVP=TRUE:mailto:projectmanager@comp
any.com
ATTENDEE;CN=teamleader@company.com;RSVP=TRUE:mailto:teamleader@company.com
END:VEVENT
We can open the exported file in Microsoft Outlook and see that the attendee list is picked up automatically.
You can download the example code here.
Cheers
Azret