WinForms Scheduler — Bi-Directional Microsoft Office 365 Synchronization

WinForms Team Blog
13 July 2023

With our most recent major update, you can seamlessly synchronize Office 365 event/appointment data with the DevExpress WinForms Scheduler component. You can now export user appointments from the WinForms Scheduler to Office 365 calendars, import Office 365 events/appointments to the Scheduler control, modify user events/appointments before synchronization, merge user appointments with Microsoft 365 calendars, resolve merge conflicts, and save changes to a database.

Sync with Microsoft Office 365 Calendars — WinForms Scheduler Control, DevExpress

Before You Start — Required Dependencies

Install the following dependency libraries (NuGet packages):

Get Started in 1-Click

Drop the WinForms Scheduler control onto a form, open its smart tag menu and select "Sync with Microsoft 365 Calendar". This creates the DXOutlook365Sync component.

Initialize DXOutlook365Sync Component — WinForms Scheduler Control, DevExpress

Incorporate Essential Data Fields and Set Up Custom Mappings

If you need to save changes to the database after synchronization between your application and Microsoft Office 365 calendars, the DXOutlook365Sync component requires five specific fields (within your data source) to store unique identifiers for Microsoft 365 events and record the last modified date of user events/appointments.

DataTable source = new DataTable();
source.Columns.AddRange(new DataColumn[] {
    new DataColumn("Subject", typeof(string)),
    new DataColumn("Description", typeof(string)),
    new DataColumn("Start", typeof(DateTime)),
    new DataColumn("End", typeof(DateTime)),
    // Special data fields.
    new DataColumn("Outlook365CalendarId", typeof(string)),
    new DataColumn("Outlook365EventId", typeof(string)),
    new DataColumn("Outlook365EventUniqId", typeof(string)),
    new DataColumn("Outlook365LastChangedUTC", typeof(DateTime)),
    new DataColumn("SchedulerLastChangedUTC", typeof(DateTime))
});

Define custom mappings to these fields to complete your data source setup.

// Defines custom mappings.
schedulerDataStorage1.Appointments.CustomFieldMappings.Add(new AppointmentCustomFieldMapping("outlook365_calendar_id", "Outlook365CalendarId"));
schedulerDataStorage1.Appointments.CustomFieldMappings.Add(new AppointmentCustomFieldMapping("outlook365_event_id", "Outlook365EventId"));
schedulerDataStorage1.Appointments.CustomFieldMappings.Add(new AppointmentCustomFieldMapping("outlook365_event_ICalUId", "Outlook365EventUniqId"));
schedulerDataStorage1.Appointments.CustomFieldMappings.Add(new AppointmentCustomFieldMapping("outlook365_lastChangedUTC", "Outlook365LastChangedUTC"));
schedulerDataStorage1.Appointments.CustomFieldMappings.Add(new AppointmentCustomFieldMapping("scheduler_lastChangedUTC", "SchedulerLastChangedUTC"));

Read our documentation for detailed information and examples: How to Save Changes to Data Source.

Initialize Sync API

You must initialize the DXOutlook365Sync component before using its APIs. Register your application in Azure and pass registration data to the InitAsync method. This method opens the "Sign in to your account" window (requiring log in to Microsoft Office 365).

Initialize Sync API — WinForms Scheduler Control, DevExpress
private async void initBarButtonItem_ItemClick(object sender, ItemClickEventArgs e) {
    string tenantId = "..."; // Enter your tenant (directory) ID.
    string clientId = "..."; // Enter your client (application) ID.
    await dxOutlook365Sync1.InitAsync(tenantId, clientId);
}

Select Microsoft 365 Calendars to Sync

The DXOutlook365Sync component can synchronize user appointments in the WinForms Scheduler control with events from all (or specific) Office 365 calendars. Its Calendars collection contains OutlookCalendarItem objects that correspond to Office365 calendars.

A calendar has the OutlookCalendarItem.EnableSynchronization setting that specifies whether to synchronize its events with user appointments in the WinForms Scheduler control.

Import Microsoft 365 Events

Use the ImportOutlookToSchedulerAsync(Boolean) method to import events from Office 365 calendars to the WinForms Scheduler control.

using DevExpress.XtraScheduler.Microsoft365Calendar;

private async void importEventsButton_Click(object sender, EventArgs e) {
    // Checks whether the initialization of 'dxOutlook365Sync1' failed.
    if(!await InitOutlook365Sync(dxOutlook365Sync1)) return;
    // Displays the wait form.
    splashScreenManager1.ShowWaitForm();
    // Imports Outlook 365 events to the Scheduler control.
    await dxOutlook365Sync1.ImportOutlookToSchedulerAsync(false);
    // Hides the wait form.
    splashScreenManager1.CloseWaitForm();
}
private async Task<bool> InitOutlook365Sync(DXOutlook365Sync outlook365sync) {
    // Initializes the 'dxOutlook365Sync1' component.
    string tenantId = "..."; // Enter your tenant (directory) ID.
    string clientId = "..."; // Enter your client (application) ID.
    InitStatus status = await outlook365sync.InitAsync(tenantId, clientId);
    // Returns false and displays a message box if the initialization of 'dxOutlook365Sync1' failed.
    if(status == InitStatus.Error) {
        XtraMessageBox.Show("Initialization of DXOutlook365Sync failed.", "Error", MessageBoxButtons.OK);
        return false;
    }
    return true;
}

Export User Appointments to Microsoft 365 Calendars

Use the ExportSchedulerToOutlookAsync(Boolean) method to export user appointments from the DevExpress Scheduler control to Office 365 calendars.

private async void exportAppointmentsButton_Click(object sender, EventArgs e) {
    // Checks whether the initialization of 'dxOutlook365Sync1' failed.
    if(!await InitOutlook365Sync(dxOutlook365Sync1)) return;
    splashScreenManager1.ShowWaitForm();
    // Exports the Scheduler control's appointments to Outlook365.
    await dxOutlook365Sync1.ExportSchedulerToOutlookAsync(false);
    splashScreenManager1.CloseWaitForm();
}

Customize Appointments or Events Before Synchronization

The following events allow you to customize a user appointment or event before synchronization:

Merge Calendars and Resolve Merge Conflicts

The DXOutlook365Sync APIs allow you to merge user appointments with Office 365 events. You can merge all events/appointments or define a rule to skip certain events/appointments (based on specific conditions).

And yes, our sync API allows you to easily resolve merge conflicts as needed.

 

Should you wish to incorporate this feature in your WinForms project, remember to follow appropriate InfoSec-related best practices: Microsoft 365 for business security best practices.

Your Feedback Matters

Please take a moment to answer the following questions. Your feedback will help us fine-tune development plans in our current release cycle.

Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.