)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to import and export schedule appointments with Outlook calendar?

Platform: Xamarin.Forms |
Control: SfSchedule |
Published Date: September 20, 2018 |
Last Revised Date: January 8, 2020

In SfSchedule, you can import and export the appointments to Outlook using Microsoft Graph.

 

Step 1:

The first step in creating an application that has access to personal information is to register it with the required service. This can be accomplished by signing into the Application Registration portal, by clicking the “Add an app button” and completing the required workflow. Note that you must add delegated permissions for User.ReadCalendars.Read and Calendars.ReadWrite. Once application registration is complete, make a note of the Application ID and URLs. 

 

Step 2:

In portable project, replace your application ID inside App.cs

 

//You need to replace your Application ID 
public static string ClientID = "61d2216e-06e6-4940-8c20-c3a923a40620"; 
public static string[] Scopes = { "User.Read", "Calendars.Read", "Calendars.ReadWrite" };

 

Step 3:

In Android project, open AndroidManifest.xml and replace your URL in data inside intent-filter

 

 <category android:name="android.intent.category.BROWSABLE" /> 
  <!--You need to replace your URL--> 
  <data android:scheme="msal61d2216e-06e6-4940-8c20-c3a923a40620" android:host="auth"/> 
</intent-filter> 

 

You also need to replace your URL in App.IdentityClientApp.RedirectUri in OnCreate override method inside MainActivity.cs.

 

//You need to replace your URL 
App.IdentityClientApp.RedirectUri = "msal61d2216e-06e6-4940-8c20-c3a923a40620://auth"; 
App.UiParent = new UIParent(Xamarin.Forms.Forms.Context as Activity); 

 

Step 4:

In iOS project, you need to register your custom URL scheme in Info.plist. Kindly refer the below steps

 

Click Info.plist.

Select ‘Advanced’ tab.

Now, click ‘Add URL Type’.

Enter the text ‘MASL’ in Identifier text block.

Enter the URL in ‘URL Schemes’ text block.

 

You also need to replace your URL in App.IdentityClientApp.RedirectUri in FinishedLaunching override method inside AppDelegate.cs 

 

LoadApplication(new App()); 
//You need to replace your URL 
App.IdentityClientApp.RedirectUri = "msal61d2216e-06e6-4940-8c20-c3a923a40620://auth"; 
return base.FinishedLaunching(app, options);  

 

In Universal Windows Platform (UWP) project, the Microsoft Authentication Library doesn’t require any specific platform modifications to handle the login process.

 

Step 5:

In our sample authentication is done by using GraphServiceClient, which will be responsible for calling all future Graph APIs. 

 

Client = new GraphServiceClient("https://graph.microsoft.com/v1.0", 
                                new DelegateAuthenticationProvider(async (requestMessage) => 
                                { 
                                    if (App.IdentityClientApp.Users == null || App.IdentityClientApp.Users.Count() == 0) 
                                        tokenRequest = awaitApp.IdentityClientApp.AcquireTokenAsync(App.Scopes, App.UiParent); 
                                    else 
                                        tokenRequest = awaitApp.IdentityClientApp.AcquireTokenSilentAsync(App.Scopes, App.IdentityClientApp.Users.FirstOrDefault()); 
                                    requestMessage.Headers.Authorization = newAuthenticationHeaderValue("bearer", tokenRequest.AccessToken); 
                                }));

 

Step 6:

You can bind appointments to the Schedule control form other sources using AppointmentMapping support. You will need to create custom appointment collection from other sources using custom data model and all the properties of the data model should be mapped to the Schedule mapping properties. Kindly refer our online User Guide Documentation by using the below links.

 

/// <summary>   
/// Represents data model properties.   
/// </summary>  
public class Meeting 
{
    public string EventName { get; set; }
    public string Organizer { get; set; }
    public DateTime From { get; set; }
    public DateTime To { get; set; }
    public bool AllDay { get; set; }
    public Color Color { get; set; }
}

 

Links:
https://help.syncfusion.com/xamarin/scheduler/data-bindings#mapping

https://help.syncfusion.com/xamarin/scheduler/data-bindings#creating-custom-appointments

 

Step 7:

Now, you can populate the appointments to the Schedule from the registered Outlook account by converting the events to appointments using AppointmentMapping support.

 

var events = await Client.Me.Events.Request().GetAsync();
var appointmentList = events.ToList();
 
this.CreateColorCollection();
var randomTime = new Random();
 
foreach (var appointment in appointmentList)
{
    viewModel.Meetings.Add(new Meeting()
    {
        From = Convert.ToDateTime(appointment.Start.DateTime).ToLocalTime(),
        To = Convert.ToDateTime(appointment.End.DateTime).ToLocalTime(),
        EventName = appointment.Subject,
    });
}

 

You can also export the Schedule appointments to Outlook by converting it as events and each event can be populated to the registered Outlook account.

 

foreach (var appointment in viewModel.Meetings)
{
    var calEvent = new Event
    {
        Subject = appointment.EventName,
 
        Start = new DateTimeTimeZone
        {
            DateTime = appointment.From.ToString("yyyy-MM-ddTHH:mm:ss"),
            TimeZone = "GMT Standard Time"
        },
        End = new DateTimeTimeZone()
        {
            DateTime = appointment.To.ToString("yyyy-MM-ddTHH:mm:ss"),
            TimeZone = "GMT Standard Time"
        },
    };
    await Client.Me.Events.Request().AddAsync(calEvent);
}

 

You can download the entire source code of this demo for Xamarin.Forms using below link,

 

Sample: ImportAndExport_Schedule_Appointments

 

You can also refer the below blogs to connect the Xamarin Forms application with Outlook using Microsoft Graph.

Links:

https://devblogs.microsoft.com/xamarin/enterprise-apps-made-easy-updated-libraries-apis/

https://devblogs.microsoft.com/xamarin/lets-schedule-meeting/

 

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
Ankita Mittal
Jan 02, 2020

Please make this sample available to me . I facing issue with same Outlook calendar in my Xamarin App.

Reply
Karthikraja Arumugam [Syncfusion]
Jan 09, 2020

Hi Ankita,

We have moved the sample to GitHub location and updated the link for the same, now you can download the sample using the provided link in the document.

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon