如何使用 C# VSTO 创建约会并显示日程安排助手视图

How to create an appointment using C# VSTO and display the Schedule Assistant view

我想添加 C# 代码(在我的 Outlook VSTO 插件中)以创建约会并在显示时显示日程安排助理视图。

下面是我到目前为止编写的创建约会、添加收件人的代码。但是当调用 Display 方法时,它显示的是默认的 Appointment 视图。我希望它显示日程安排助理视图并显示我刚添加的收件人。

AppointmentItem newAppointment = Application.CreateItem(OlItemType.olAppointmentItem);

Recipients sentTo = newAppointment.Recipients;
Recipient sentInvite = null;
sentInvite = sentTo.Add(emailAddress);
sentInvite.Type = (int)OlMeetingRecipientType.olRequired;
sentTo.ResolveAll();
newAppointment.Display();

更新

在我的 VSTO 加载项项目中,我添加了一个 UserControl。在这个 UserControl 中,我有一个 Button 控件。单击按钮时,它会运行以下代码:

AppointmentItem newAppointment = Globals.ThisAddIn.Application.CreateItem(OlItemType.olAppointmentItem);
newAppointment.MeetingStatus = OlMeetingStatus.olMeeting;

Inspector inspector = newAppointment.GetInspector;
CommandBarControl commandBarControl = inspector.CommandBars.FindControl(Type.Missing, 14935);
commandBarControl.Execute();

Recipients recipients = newAppointment.Recipients;
Recipient readyByRecipient = null;
readyByRecipient = recipients.Add(emailAddress);
readyByRecipient.Type = (int)OlMeetingRecipientType.olRequired;
recipients.ResolveAll();
newAppointment.Display();

Marshal.ReleaseComObject(readyByRecipient);
Marshal.ReleaseComObject(recipients);
Marshal.ReleaseComObject(newAppointment);

不幸的是,当我调用 FindControl 方法(从 OutlookAppointmentItemControls.xlsx 文件传递​​ ID 值)时它 returns 为空,所以我无法调用 commandBarControl.Execute() 来显示日程安排助理查看。

而且我也试过在调用 newAppointment.Display() 之后调用 FindControl 方法,但它仍然 returns 为空。

您需要在调用 Display 方法之前将 AppointmentItem class 的 MeetingStatus 属性 设置为 olMeeting 值。例如:

Sub CreateAppt()
  Dim myItem As Object 
  Dim myRequiredAttendee, myOptionalAttendee, myResourceAttendee As Outlook.Recipient 
  Set myItem = Application.CreateItem(olAppointmentItem)  
  myItem.MeetingStatus = olMeeting 
  myItem.Subject = "Strategy Meeting"
  myItem.Location = "Conference Room B" 
  myItem.Start = #9/24/2015 1:30:00 PM# 
  myItem.Duration = 90  
  Set myRequiredAttendee = myItem.Recipients.Add("Nate Sun")  
  myRequiredAttendee.Type = olRequired  
  Set myOptionalAttendee = myItem.Recipients.Add("Kevin Kennedy")  
  myOptionalAttendee.Type = olOptional  
  Set myResourceAttendee = myItem.Recipients.Add("Conference Room B")  
  myResourceAttendee.Type = olResource  
  myItem.Display  
End Sub

要查看“日程安排助理”视图,您可以通过编程方式运行 功能区上的相应按钮。 CommandBars class 的执行方法可用于 运行 计划按钮。您只需要传递内置控件的 idMso 即可。有关实际值,请参阅 Office 2013 Help Files: Office Fluent User Interface Control Identifiers

成功了。解决方案是使用 OutlookAppointmentItemControls.xlsx 文件中的控件名称值调用 ExecuteMso 方法。而且它似乎只有在调用 Display 方法后调用 ExecuteMso 才有效。

下面的代码用于创建与收件人的新约会(会议),并在检查器中显示日程安排助手视图 window。

AppointmentItem newAppointment = Globals.ThisAddIn.Application.CreateItem(OlItemType.olAppointmentItem);
newAppointment.MeetingStatus = OlMeetingStatus.olMeeting;

Recipients recipients = newAppointment.Recipients;
Recipient readyByRecipient = null;
readyByRecipient = recipients.Add(emailAddress);
readyByRecipient.Type = (int)OlMeetingRecipientType.olRequired;
recipients.ResolveAll();
newAppointment.Display();

Inspector inspector = newAppointment.GetInspector;
inspector.CommandBars.ExecuteMso("ShowSchedulingPage");

Marshal.ReleaseComObject(readyByRecipient);
Marshal.ReleaseComObject(recipients);
Marshal.ReleaseComObject(newAppointment);
Marshal.ReleaseComObject(inspector);