我在 Outlook 中创建会议时使用以下代码
private void ThisAddIn_Startup(object sender, EventArgs e)
{
//other code
Application.ItemSend += Application_ItemSend;
}
private void Application_ItemSend(object item, ref bool cancel)
{
if (item is MeetingItem meetingItem)
{
//some code
}
}
此功能仅在我发送消息时才起作用,但如果我只是保存更改并关闭窗口,则此功能不起作用。 我尝试使用此代码,因为应用程序没有保存事件
private void ThisAddIn_Startup(object sender, EventArgs e)
{
//other code
Application.ItemSend += Application_ItemSend;
Application.ItemLoad += Application_ItemLoad;
}
private void Application_ItemLoad(object item)
{
if (item is MeetingItem meetingItem)
{
meetingItem.Write += (ref bool Cancel) => MeetingItem_Write(meetingItem, ref Cancel);
}
}
private void MeetingItem_Write(MeetingItem meetingItem, ref bool Cancel)
{
if (string.IsNullOrEmpty(meetingItem.Body))
{
//some code
}
}
但是写入事件没有被触发。 我一定是做错了什么。 我需要实现此功能来检查会议正文在保存时是否为空。如果主体为空或为 null,则对其进行更改。
首先,如果您正在编辑“日历”文件夹中的项目,您处理的是
AppointmentItem
对象,而不是 MeetingItems
。 MeetingItem
对象仅被发送或接收。
其次,如果您想跟踪更改,请订阅
Items.ItemChange
事件,其中 Items 来自 MAPIFolder.Items
属性,而 MAPIFolder
是从 Applicatiobn.Session.GetDefaultFolder(olFolderCalendar)
检索的。