Back to Devexpress

ISchedulerStorageBase.CreateOutlookExporter() Method

corelibraries-devexpress-dot-xtrascheduler-dot-ischedulerstoragebase.md

latest6.8 KB
Original Source

ISchedulerStorageBase.CreateOutlookExporter() Method

Creates an object which provides the capability to control how data is exported to MS Outlook’s Calendar.

Namespace : DevExpress.XtraScheduler

Assembly : DevExpress.XtraScheduler.v25.2.Core.dll

NuGet Package : DevExpress.Scheduler.Core

Declaration

csharp
AppointmentExporter CreateOutlookExporter()
vb
Function CreateOutlookExporter As AppointmentExporter

Returns

TypeDescription
AppointmentExporter

An AppointmentExporter object which can export data to MS Outlook’s Calendar.

|

Remarks

Although you can use the ISchedulerStorageBase.ExportToOutlook method for data export to MS Outlook’s Calendar, use the CreateOutlookExporter method if you need to control how appointments are posted to the MS Outlook’s Calendar. Call this method to create an AppointmentExporter object and subscribe to its events to control export operations.

Note

For data synchronization, use the AppointmentSynchronizer class descendant instead. It is created by the ISchedulerStorageBase.CreateOutlookExportSynchronizer method. Refer to the Synchronization with Microsoft Outlook article for more information.

Example

This code illustrates how to use the OutlookExport class to manage the process of exporting appointments to MS Outlook. Use the SchedulerDataStorage.CreateOutlookExporter method to create the exporter, subscribe to its AppointmentExporter.AppointmentExporting, AppointmentExporter.AppointmentExported and AppointmentExchanger.OnException events and call the AppointmentExporter.Export method.

csharp
private void ExportUsingCriteria() {
    OutlookExport exporter = schedulerControl1.Storage.CreateOutlookExporter() as OutlookExport;
    if (exporter != null) {
        exporter.AppointmentExporting += exporter_AppointmentExporting;
        exporter.AppointmentExported += exporter_AppointmentExported;
        exporter.OnException += exporter_OnException;
        exporter.CalendarFolderName = OutlookExchangeHelper.GetOutlookCalendarFolders().FirstOrDefault().FullPath;
        using (MemoryStream stream = new MemoryStream()) {
            exporter.Export(stream);
        }
    }
}
void exporter_AppointmentExporting(object sender, AppointmentExportingEventArgs e) {
    AddToLog(String.Format("Exporting Subj:{0}, started at {1:F} ...", e.Appointment.Subject, e.Appointment.Start));
    if (e.Appointment.IsRecurring) {
        e.Cancel = true;
        AddToLog("Cancelled because of its type (recurring).");
    }
}
void exporter_AppointmentExported(object sender, AppointmentExportedEventArgs e) {
    AddToLog(String.Format("Successfully exported Subj:{0}, started at {1:F}!", e.Appointment.Subject, e.Appointment.Start)); 
}
void exporter_OnException(object sender, ExchangeExceptionEventArgs e) {
    string errText = e.OriginalException.Message;
    AddToLog(errText);
    OutlookExport exporter = (OutlookExport)sender;
    exporter.Terminate();
    e.Handled = true;
    //throw e.OriginalException;
}
vb
Private Sub ExportUsingCriteria()
    Dim exporter As OutlookExport = TryCast(schedulerControl1.Storage.CreateOutlookExporter(), OutlookExport)
    If exporter IsNot Nothing Then
        AddHandler exporter.AppointmentExporting, AddressOf exporter_AppointmentExporting
        AddHandler exporter.AppointmentExported, AddressOf exporter_AppointmentExported
        AddHandler exporter.OnException, AddressOf exporter_OnException
        exporter.CalendarFolderName = OutlookExchangeHelper.GetOutlookCalendarFolders().FirstOrDefault().FullPath
        Using stream As New MemoryStream()
            exporter.Export(stream)
        End Using
    End If
End Sub
Private Sub exporter_AppointmentExporting(ByVal sender As Object, ByVal e As AppointmentExportingEventArgs)
    AddToLog(String.Format("Exporting Subj:{0}, started at {1:F} ...", e.Appointment.Subject, e.Appointment.Start))
    If e.Appointment.IsRecurring Then
        e.Cancel = True
        AddToLog("Cancelled because of its type (recurring).")
    End If
End Sub
Private Sub exporter_AppointmentExported(ByVal sender As Object, ByVal e As AppointmentExportedEventArgs)
    AddToLog(String.Format("Successfully exported Subj:{0}, started at {1:F}!", e.Appointment.Subject, e.Appointment.Start))
End Sub
Private Sub exporter_OnException(ByVal sender As Object, ByVal e As ExchangeExceptionEventArgs)
    Dim errText As String = e.OriginalException.Message
    AddToLog(errText)
    Dim exporter As OutlookExport = DirectCast(sender, OutlookExport)
    exporter.Terminate()
    e.Handled = True
    'throw e.OriginalException;
End Sub

See Also

CreateOutlookExportSynchronizer()

CreateOutlookImporter()

ExportToVCalendar

Synchronization with Microsoft Outlook

ISchedulerStorageBase Interface

ISchedulerStorageBase Members

DevExpress.XtraScheduler Namespace