Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a new meeting request to an Outlook calendar using interop?

Ok, I am trying to connect to a shared Outlook Calendar in C# using Interop and add a new meeting request.

Here's what I've got so far, starting with my using statements (this is a Windows form):

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using System.Windows.Forms;
using Outlook = Microsoft.Office.Interop.Outlook;

Then I have a public class called "Appointments" which is below:

public class Appointments
{
    public string ConversationTopic { get; set; }
    public int Duration { get; set; }
    public DateTime StartTime { get; set; }
    public DateTime EndTime { get; set; }
    public string Organizer { get; set; }
    public int ReminderMinutesBeforeStart { get; set; }
    public string RequiredAttendees { get; set; }
    public string Subject { get; set; }
    public string Body { get; set; }
}

I have a new blank windows form with a Data Grid View currently called dataGridView1. The form load event code is below:

private void Form1_Load(object sender, EventArgs e)
{
    Outlook.Application oApp;
    oApp = new Outlook.Application();
    Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
    oNS.Logon(Missing.Value, Missing.Value, true, true);

    Outlook.Recipient oRecip = (Outlook.Recipient)oNS.CreateRecipient("Foo bar");
    Outlook.MAPIFolder oFolder = (Outlook.MAPIFolder) oNS.GetSharedDefaultFolder(oRecip, Outlook.OlDefaultFolders.olFolderCalendar);

    List<Appointments> appointmentList = new List<Appointments>();

    foreach (object item in oFolder.Items)
    {
        Outlook.AppointmentItem thisOne = (Outlook.AppointmentItem)item;
        appointmentList.Add(new Appointments { ConversationTopic = thisOne.ConversationTopic, Duration = thisOne.Duration, EndTime = thisOne.End, Organizer = thisOne.Organizer, ReminderMinutesBeforeStart = thisOne.ReminderMinutesBeforeStart, RequiredAttendees = thisOne.RequiredAttendees, StartTime = thisOne.Start, Subject = thisOne.Subject, Body = thisOne.Body });
    }

    dataGridView1.AutoGenerateColumns = true;
    dataGridView1.DataSource = appointmentList;
    dataGridView1.Sort(dataGridView1.Columns["Subject"], ListSortDirection.Descending);
}

This works flawlessly in connecting to my calendar and filling my Data Grid View with all of my relevant calendar information. Now I want to programmatically send a new Meeting Request to the calendar.

I'm guessing a Meeting Request is an oFolder.Item so I think I want to type:

oFolder.Items.Add(* details here *);

Inside the brackets, intellisense simply says the following:

dynamic_Items.Add([object Type = Type.Missing])

Now I'm stumped and help would be much appreciated.

Thanks

like image 483
JMK Avatar asked Feb 09 '12 19:02

JMK


People also ask

How do you add an invite to an already scheduled meeting in Outlook?

In your Outlook calendar, click on the New Meeting icon in the ribbon. In the new meeting windows that opens, Click on Scheduling Assistant. Click on the Add Attendees button at the bottom left of the Attendees list. In the Select Attendees and Resources window, you can add people as required or optional.


1 Answers

using Outlook = Microsoft.Office.Interop.Outlook;    

private void SetRecipientTypeForAppt()
    {
        Outlook.AppointmentItem appt =
            Application.CreateItem(
            Outlook.OlItemType.olAppointmentItem)
            as Outlook.AppointmentItem;
        appt.Subject = "Customer Review";
        appt.MeetingStatus = Outlook.OlMeetingStatus.olMeeting;
        appt.Location = "36/2021";
        appt.Start = DateTime.Parse("10/20/2006 10:00 AM");
        appt.End = DateTime.Parse("10/20/2006 11:00 AM");
        Outlook.Recipient recipRequired =
            appt.Recipients.Add("Ryan Gregg");
        recipRequired.Type =
            (int)Outlook.OlMeetingRecipientType.olRequired;
        Outlook.Recipient recipOptional =
            appt.Recipients.Add("Peter Allenspach");
        recipOptional.Type =
            (int)Outlook.OlMeetingRecipientType.olOptional;
        Outlook.Recipient recipConf =
           appt.Recipients.Add("Conf Room 36/2021 (14) AV");
        recipConf.Type =
            (int)Outlook.OlMeetingRecipientType.olResource;
        appt.Recipients.ResolveAll();
        appt.Display(false);
    }

via How to: Create a Meeting Request, Add Recipients, and Specify a Location

like image 85
Ta01 Avatar answered Oct 24 '22 00:10

Ta01