corelibraries-devexpress-dot-xtrascheduler-dot-ischedulerstoragebase-cdca8377.md
Creates an object which allows you to control how data is imported from MS Outlook’s Calendar.
Namespace : DevExpress.XtraScheduler
Assembly : DevExpress.XtraScheduler.v25.2.Core.dll
NuGet Package : DevExpress.Scheduler.Core
AppointmentImporter CreateOutlookImporter()
Function CreateOutlookImporter As AppointmentImporter
| Type | Description |
|---|---|
| AppointmentImporter |
An object which can import data from MS Outlook’s Calendar.
|
Although you can import data from Outlook’s Calendar via the ISchedulerStorageBase.ImportFromOutlook method, use the CreateOutlookImporter method to control how appointments are retrieved from MS Outlook’s Calendar. Call this method to create an AppointmentImporter object, and subscribe to its events to control import operations.
Note
For data synchronization use the AppointmentSynchronizer class descendant instead. It is created by ISchedulerStorageBase.CreateOutlookImportSynchronizer method. Refer to Synchronization with Microsoft Outlook article for more information.
This code illustrates how to use the OutlookImport class to manage the process of importing appointments from MS Outlook. Use the SchedulerDataStorage.CreateOutlookImporter method to create the importer, subscribe to its AppointmentImporter.AppointmentImporting, AppointmentImporter.AppointmentImported and AppointmentExchanger.OnException events and call the AppointmentImporter.Import method.
private void ImportUsingCriteria() {
OutlookImport importer = schedulerControl1.Storage.CreateOutlookImporter() as OutlookImport;
if (importer != null) {
importer.AppointmentImporting += importer_AppointmentImporting;
importer.AppointmentImported += importer_AppointmentImported;
importer.OnException += importer_OnException;
importer.CalendarFolderName = OutlookExchangeHelper.GetOutlookCalendarFolders().FirstOrDefault().FullPath;
using (MemoryStream stream = new MemoryStream()) {
importer.Import(stream);
}
}
}
void importer_AppointmentImporting(object sender, AppointmentImportingEventArgs e) {
OutlookAppointmentImportingEventArgs args = e as OutlookAppointmentImportingEventArgs;
AddToLog(String.Format("Importing Subj:{0}, started at {1:F} ...", args.OutlookAppointment.Subject, args.OutlookAppointment.Start));
if (args.OutlookAppointment.BusyStatus == DevExpress.XtraScheduler.Outlook.Interop.OlBusyStatus.olWorkingElsewhere) {
e.Cancel = true;
AddToLog("Cancelled because of its busy type (working elsewhere).");
}
}
void importer_AppointmentImported(object sender, AppointmentImportedEventArgs e) {
OutlookAppointmentImportedEventArgs args = e as OutlookAppointmentImportedEventArgs;
AddToLog(String.Format("Successfully imported Subj:{0}, started at {1:F}!", args.OutlookAppointment.Subject, args.OutlookAppointment.Start));
}
void importer_OnException(object sender, ExchangeExceptionEventArgs e) {
string errText = e.OriginalException.Message;
AddToLog(errText);
OutlookImport importer = (OutlookImport)sender;
importer.Terminate();
e.Handled = true;
//throw e.OriginalException;
}
Private Sub ImportUsingCriteria()
Dim importer As OutlookImport = TryCast(schedulerControl1.Storage.CreateOutlookImporter(), OutlookImport)
If importer IsNot Nothing Then
AddHandler importer.AppointmentImporting, AddressOf importer_AppointmentImporting
AddHandler importer.AppointmentImported, AddressOf importer_AppointmentImported
AddHandler importer.OnException, AddressOf importer_OnException
importer.CalendarFolderName = OutlookExchangeHelper.GetOutlookCalendarFolders().FirstOrDefault().FullPath
Using stream As New MemoryStream()
importer.Import(stream)
End Using
End If
End Sub
Private Sub importer_AppointmentImporting(ByVal sender As Object, ByVal e As AppointmentImportingEventArgs)
Dim args As OutlookAppointmentImportingEventArgs = TryCast(e, OutlookAppointmentImportingEventArgs)
AddToLog(String.Format("Importing Subj:{0}, started at {1:F} ...", args.OutlookAppointment.Subject, args.OutlookAppointment.Start))
If args.OutlookAppointment.BusyStatus = DevExpress.XtraScheduler.Outlook.Interop.OlBusyStatus.olWorkingElsewhere Then
e.Cancel = True
AddToLog("Cancelled because of its busy type (working elsewhere).")
End If
End Sub
Private Sub importer_AppointmentImported(ByVal sender As Object, ByVal e As AppointmentImportedEventArgs)
Dim args As OutlookAppointmentImportedEventArgs = TryCast(e, OutlookAppointmentImportedEventArgs)
AddToLog(String.Format("Successfully imported Subj:{0}, started at {1:F}!", args.OutlookAppointment.Subject, args.OutlookAppointment.Start))
End Sub
Private Sub importer_OnException(ByVal sender As Object, ByVal e As ExchangeExceptionEventArgs)
Dim errText As String = e.OriginalException.Message
AddToLog(errText)
Dim importer As OutlookImport = DirectCast(sender, OutlookImport)
importer.Terminate()
e.Handled = True
'throw e.OriginalException;
End Sub
See Also
Synchronization with Microsoft Outlook