0

So I've been looking into programmatically creating calendar events for the Outlook Calendar.

I looked at the documentation here and here.

Are there any step-by-steps regarding asp.net webforms to display on .ASPX pages or exemplars of code targeted for that domain.

I tried following this example in adding an appointment to the calendar but I receive the error 'HttpApplicationState does not contain a definition for 'CreateItem' and no accessible extension method 'CreateItem' accepting a first argument of type 'HttpApplicationState' could be found (are you missing a using directive or an assembly reference?)

private void AddAppointment()
{
    try
    {
        Outlook.AppointmentItem newAppointment = (Outlook.AppointmentItem)
        Application.CreateItem(Outlook.OlItemType.olAppointmentItem);
        newAppointment.Start = DateTime.Now.AddHours(2);
        newAppointment.End = DateTime.Now.AddHours(3);
        newAppointment.Location = "ConferenceRoom #2345";
        newAppointment.Body = "We will discuss progress on the group project.";
        newAppointment.AllDayEvent = false;
        newAppointment.Subject = "Group Project";
        newAppointment.Recipients.Add("Roger Harui");
        Outlook.Recipients sentTo = newAppointment.Recipients;
        Outlook.Recipient sentInvite = null;
        sentInvite = sentTo.Add("Holly Holt");
        sentInvite.Type = (int)Outlook.OlMeetingRecipientType.olRequired;
        sentInvite = sentTo.Add("David Junca ");
        sentInvite.Type = (int)Outlook.OlMeetingRecipientType.olOptional;
        sentTo.ResolveAll();
        newAppointment.Save();
        newAppointment.Display(true);
    }
    catch (Exception ex)
    {
        Console.WriteLine("The following error occurred: " + ex.Message);
    }
}

These are my using's:

using System;
using Outlook = Microsoft.Office.Interop.Outlook;

Have I just come at this completely wrong?

EDIT #1: I want to integrate the outlook calendar into the website so that users can add an appointment to their outlook calendar. I'm looking for concise documentation to achieve this in C# on an ASP.NET webforms site, and most of the documentation is for Microsoft.Office.Interop which doesn't seem to work locally for me.

  • What is the problem you are trying to solve? Do you want to enable the users of your website to add an appointment to their calendar? With the approach you show in your question, the server tries to access outlook. From my experience, it is highly unlikely that Outlook is installed on the server. This might explain the error. It would be helpful if you'd explain your scenario in greater detail to find the right approach. – Markus Dec 03 '18 at 14:40
  • Hello @Markus, I appended an edit to the post, maybe that is helpful - basically I don't know where to start with the integration of outlook allowing users of the site to add appointments to their outlook calendar directly. I seek to integrate the outlook calendar with the site directly, but using Interop it doesn't seem to work as per the documentation link in the post. –  Dec 03 '18 at 14:44

1 Answers1

0

The code you show in your sample is executed on the server. Usually, Outlook is not installed on the server so that you receive an error. Also, the user context on the server is often one of a service account, not of the user that initiated the request. Usually, there are different approaches that are used to create calendar items.

An easy way to enable the users of your website to add an appointment to their calendar (independent of the program they use) is to download an iCalendar-file (ICS) from your website by clicking a link on your site. This file is opened on the client and the users can save the appointment in the calendar application they use. There are various nuget packages that support you in creating the files.

You could also add a specific "Add to Outlook calendar" function to your site if it is an internal application for a company so that you know some details about the infrastructure. For instance, if the company uses Office 365, you could use Microsoft Graph to create a calendar item.

If the company uses an Exchange server, you could also use Exchange Web Services (EWS) to access an exchange server and create the appointment without using Outlook.

Markus
  • 20,838
  • 4
  • 31
  • 55
  • Hello Markus, thank you for taking the time out of your day to help me. I believe the best way to go may be EWS. –  Dec 03 '18 at 15:16