如何使用interop将新的会议请求添加到Outlook日历中
本文关键字:添加 Outlook 日历 请求 会议 interop 何使用 | 更新日期: 2023-09-27 18:23:52
好的,我正在尝试使用Interop连接到C#中的共享Outlook日历,并添加一个新的会议请求。
以下是到目前为止我得到的内容,从我的使用语句开始(这是一个Windows表单):
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using System.Windows.Forms;
using Outlook = Microsoft.Office.Interop.Outlook;
然后我有一个名为"预约"的公共课程,如下所示:
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; }
}
我有一个新的空白窗口窗体,其数据网格视图当前名为dataGridView1。表单加载事件代码如下:
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);
}
这可以完美地连接到我的日历,并用我的所有相关日历信息填充我的数据网格视图。现在,我想以编程方式向日历发送一个新的会议请求。
我猜会议请求是oFolder.项目,所以我想我想键入:
oFolder.Items.Add(* details here *);
在括号内,intellisense简单地说如下:
dynamic_Items.Add([object Type=Type.Missing])
现在我被难住了,我们将不胜感激。
感谢
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);
}
通过如何:创建会议请求、添加收件人和指定位置