Skip to main content
A newer version of this page is available. .

How to: Import Data from iCalendar (legacy)

  • 3 minutes to read

Note

You are viewing documentation for the legacy WPF Scheduler control. If you’re starting a new project, we strongly recommend that you use a new control declared in the DevExpress.Xpf.Scheduling namespace. If you decide to upgrade an existing project in order to switch to the updated scheduler control, see the Migration Guidelines document.

Import Data on Button Click

The following example demonstrates how to load appointment data to a scheduler from the iCalendar format on a button click. To do this, create an iCalendarImporter class instance in the Button.Click event handler and call the AppointmentImporter.Import method with a parameter set to a stream that specifies the .ics file selected by an end-user.

private void Import_Button_Click(object sender, RoutedEventArgs e) {
    OpenFileDialog dialog = new OpenFileDialog();
    dialog.Filter = "iCalendar files (*.ics)|*.ics";
    dialog.FilterIndex = 1;
    if (dialog.ShowDialog() != true)
        return;

    using (Stream stream = dialog.OpenFile()) {
        ImportAppointments(stream);
    }
}
private void ImportAppointments(Stream stream) {
    if (stream == null)
        return;
    schedulerControl1.Storage.AppointmentStorage.Clear();
    iCalendarImporter importer = new iCalendarImporter(schedulerControl1.Storage.InnerStorage);
    importer.Import(stream);
}

As a result, clicking the Import button will invoke the Open dialog where an end-user can select an iCalendar file to import appointment data to a scheduler.

DXScheduler_iCalendar_Import

Import Data on iCalendar File Drop

The following example demonstrates how to provide end-users with the capability to import appointment data to a scheduler from the iCalendar format by dragging an .ics file onto a scheduler area. To do this, create an iCalendarImporter class instance in the SchedulerControl.Drop event handler and call the AppointmentImporter.Import method with a parameter set to a stream that specifies the iCalendar file dropped by an end-user.

private void schedulerControl1_Drop(object sender, DragEventArgs e) {
    string[] fileNames = e.Data.GetData(DataFormats.FileDrop) as string[];
    if (fileNames == null || fileNames.Length == 0)
        return;

    foreach (string fileName in fileNames) {
        if (File.Exists(fileName)) {
            using (Stream stream = File.Open(fileName, FileMode.Open)) {
                ImportAppointments(stream);
            }
        }
    }
}
private void ImportAppointments(Stream stream) {
    if (stream == null)
        return;
    schedulerControl1.Storage.AppointmentStorage.Clear();
    iCalendarImporter importer = new iCalendarImporter(schedulerControl1.Storage.InnerStorage);
    importer.Import(stream);
}

As a result, end-users can populate a scheduler with appointment data by dragging and dropping an iCalendar file onto the scheduler area.

DXScheduler_iCalendar_Import_Drop

See Also