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
via How to: Create a Meeting Request, Add Recipients, and Specify a Location