gpt4 book ai didi

c# - 如何使用互操作将新的 session 请求添加到 Outlook 日历?

转载 作者:太空狗 更新时间:2023-10-30 00:20:46 25 4
gpt4 key购买 nike

好的,我正在尝试使用 Interop 在 C# 中连接到共享的 Outlook 日历并添加新的 session 请求。

从我的 using 语句开始(这是一个 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)如下:

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 的数据 GridView 。表单加载事件代码如下:

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);
}

这可以完美地连接到我的日历并使用我的所有相关日历信息填充我的数据 GridView 。现在我想以编程方式向日历发送新的 session 请求。

我猜 session 请求是一个 oFolder.Item,所以我想输入:

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);
}

通过如何:Create a Meeting Request, Add Recipients, and Specify a Location

关于c# - 如何使用互操作将新的 session 请求添加到 Outlook 日历?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9217396/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com