Tutorial: Loading Calendar Appointments from Exchange Server (ASP.NET WebForms)

This tutorial shows how to load calendar appointments from Exchange Server (or Office 365 Calendar) and display them using DayPilot Event Calendar in ASP.NET
Apr 4, 2016
asp.net calendar exchange office 365 ews

Features

  • Accessing Microsoft Exchange Server 2007+ (including hosted Exchange and Office 365)
  • Uses Exchange Web Services Managed API
  • C# and VB.NET source code
  • Includes open-source DayPilot Lite for ASP.NET WebForms
  • Loading events
  • Updating events
  • Creating events
  • Sample Visual Studio 2013 solution available for download

Source code of the tutorial is available for download.

Example: Loading Exchange Appointments using EWS (C#, VB.NET)

asp.net-calendar-exchange-office-365-preview.png

C#

// Exchange connection
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
service.Credentials = new WebCredentials("user@yourcompany.com", "password");   // replace with proper username and password
service.Url = new Uri("https://outlook.office365.com/ews/exchange.asmx");   // Office 365 Exchange API URL (replace it with a local server URL if you are using a local Exchange installation)

// this week
DateTime startDate = DayPilot.Utils.Week.FirstDayOfWeek();
DateTime endDate = startDate.AddDays(7);

// load the default calendar
CalendarFolder calendar = CalendarFolder.Bind(Service, WellKnownFolderName.Calendar, new PropertySet());

// load events
CalendarView cView = new CalendarView(startDate, endDate, 50);
cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End, AppointmentSchema.Id);
FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);

VB

Dim svc As New ExchangeService(ExchangeVersion.Exchange2010)
svc.Credentials = New WebCredentials("user@yourcompany.com", "password")
svc.Url = New Uri("https://outlook.office365.com/ews/exchange.asmx")

Dim startDate As Date = DayPilot.Utils.Week.FirstDayOfWeek()
Dim endDate As Date = startDate.AddDays(7)

Dim calendar As CalendarFolder = CalendarFolder.Bind(svc, WellKnownFolderName.Calendar, New PropertySet())

Dim cView As New CalendarView(startDate, endDate, 50)
cView.PropertySet = New PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End, AppointmentSchema.Id)
Dim appointments As FindItemsResults(Of Appointment) = calendar.FindAppointments(cView)

DayPilot for JavaScript, ASP.NET WebForms, ASP.NET MVC, Java