Skip to main content
All docs
V23.2

DXOutlook365Sync.InitAsync(String, String) Method

Initializes the DXOutlook365Sync component.

Namespace: DevExpress.XtraScheduler.Microsoft365Calendar

Assembly: DevExpress.XtraScheduler.v23.2.Microsoft365Calendar.dll

NuGet Package: DevExpress.Scheduler.Core.Desktop.Microsoft365Calendar

Declaration

public Task<InitStatus> InitAsync(
    string tenantId = null,
    string clientId = null
)

Optional Parameters

Name Type Default Description
tenantId String null

A tenant (directory) ID.

clientId String null

A client (application) ID.

Returns

Type Description
Task<InitStatus>

A value that indicates the result of initialization.

Remarks

Call the InitAsync method to initialize the DXOutlook365Sync component. The method opens a Sign in to your account window, which requires you to log in to Microsoft 365.

Sign In - WinForms Synchronization with Outlook 365 Calendars

The InitAsync method requires tenant and client IDs for initialization. To obtain these IDs, register your application in Azure as demonstrated in the following topic: Register an application with the Microsoft identity platform.

private async Task<InitStatus> InitComponent() {
    string tenantId = "..."; // Enter your tenant (directory) ID.
    string clientId = "..."; // Enter your client (application) ID.
    return await dxOutlook365Sync1.InitAsync(tenantId, clientId);
}

The InitAsync method returns an InitStatus enumeration value that indicates whether the initialization succeeded, failed, or has already been initialized. The InitAsync method does nothing if the DXOutlook365Sync component has already been initialized.

The DXOutlook365Sync component automatically populates its Calendars collection if the initialization was successful. This collection contains OutlookCalendarItem objects that correspond to Office365 calendars.

Example: How to Import Outlook 365 Events

This example demonstrates how to import events from all Outlook 365 calendars to the WinForms Scheduler control.

using DevExpress.XtraScheduler.Microsoft365Calendar;

DXOutlook365Sync dxOutlook365Sync1;
public Form1() {
    InitializeComponent();
    dxOutlook365Sync1 = new DXOutlook365Sync(schedulerDataStorage1);
    dxOutlook365Sync1.InitComplete += DxOutlook365Sync1_InitComplete;
}
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;
}
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();
}

The DXOutlook365Sync component raises the InitComplete event once its initialization is finished (see the following example). The e.InitStatus parameter specifies whether the initialization succeeded or failed. Use the e.Exception property to get the description of the exception.

Example: How to Export Appointments to Outlook365

using DevExpress.XtraScheduler.Microsoft365Calendar;

DXOutlook365Sync dxOutlook365Sync1;
public Form1() {
    InitializeComponent();
    dxOutlook365Sync1 = new DXOutlook365Sync(schedulerDataStorage1);
    dxOutlook365Sync1.InitComplete += DxOutlook365Sync1_InitComplete;
}
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 if the initialization of 'dxOutlook365Sync1' failed.
    return status != InitStatus.Error;
}
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();
}
private void DxOutlook365Sync1_InitComplete(object sender, InitCompleteEventArgs e) {
    if(e.InitStatus == InitStatus.Error)
        XtraMessageBox.Show(String.Format("Initialization of DXOutlook365Sync failed. {0}", e.Exception.Message), "Error", MessageBoxButtons.OK);
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the InitAsync(String, String) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also