Monday, 21 August 2017

Create calendar event in Office 365 group using EWS

As Office 365 Group (Unified Group) is robustly becoming the base service for many of Office 365 features (i.e. Planner, MS Teams, etc..) managing planner team meetings and users appointment in group calendar is inevitable now. In this post, I am going to share .net based C# code to create meeting in Office 365 Group using Managed Exchange Web Services Api (EWS).

Before proceed, you have to download Microsoft Exchange Web Services Managed API 2.0 dll and add as reference in your C# project.
ExchangeService exchService = new ExchangeService(ExchangeVersion.Exchange2013_SP1); 
exchService.UseDefaultCredentials = false; 
exchService.Credentials = new NetworkCredential("admin@o365domain.com", "pwd"); 
exchService.Url = new Uri("https://outlook.office365.com/Ews/Exchange.asmx"); 
exchService.PreAuthenticate = false; 
  
Appointment appointment = new Appointment(exchService); 
// Set the properties on the appointment object to create the appointment. 
appointment.Subject = "Sales Meeting"; 
appointment.Body = "Focus on pre-sale and marketing."; 
appointment.Start = DateTime.Now.AddDays(2); 
appointment.End = DateTime.Now.AddDays(2).AddHours(3); 
appointment.Location = "Room 111"; 
appointment.ReminderMinutesBeforeStart = 240; 
appointment.RequiredAttendees.Add("user1@o365domain.onmicrosoft.co"); 
appointment.RequiredAttendees.Add("user2@o365domain.onmicrosoft.co"); 
// Bind the specified group calendar folder. 
Folder calendar_Folder = Folder.Bind(exchService, new FolderId(WellKnownFolderName.Calendar, "salesboard@o365domain.com")); 
appointment.Save(calendar_Folder.Id, SendInvitationsMode.SendToNone);
The parameter SendInvitationsMode specifies how meeting invitations to be send to its attendees. It includes following options:

  • SendToNone : Do not send meeting invitations.
  • SendOnlyToAll : Send meeting invitations to all attendees but do not save a copy of the meeting invitation in the organizer's Sent Items folder.
  • SendToAllAndSaveCopy " Send meeting invitations to all attendees and save a copy of the meeting invitation in the organizer's Sent Items folder.

Note: AFAIK, using Exchange Web Service (EWS) we can create only meeting not appointment in office 365 group.

Advertisements
Advertisements

No comments:

Post a Comment