I have a small VSTO add-in that I've used with Outlook 2010 for some time. A move to Office 2013/Outlook 2013 is soon happening and so the add-in needs to be re-written to work with Outlook 2013.
The Outlook add-in is triggered by a custom ribbon button. When triggered, the add-in will create a new meeting request window and fill the message body with some custom content. After which the user can complete the meeting request and send it if they so desire.
The issue I'm currently having is that previously, this message window was created using the CommandBarControl object to programmatically trigger a click of the "New Meeting" button in Outlook. This worked in previous versions of Outlook, but I gather that the CommandBarControl object has been removed from Outlook 2013 and now fails silently. This is indeed what I am seeing.
The original code that was being used to create the new meeting request is this:
Explorer activeExplorer = Globals.ThisAddIn.Application.ActiveExplorer();
CommandBarControl commandBarControl = activeExplorer.CommandBars.FindControl(Type.Missing, 1106);
commandBarControl.Execute();
appointmentItem = (AppointmentItem)Globals.ThisAddIn.Application.ActiveInspector().CurrentItem;
appointmentItem.MeetingStatus = OlMeetingStatus.olMeeting;
appointmentItem.RTFBody = message; // message is a byte array being passed in from elsewhere.
The FindControl() method is used to find the "New Meeting" button in Outlook and then Execute() a click action on that button.
An alternative might be something like this:
appointmentItem = (AppointmentItem)Globals.ThisAddIn.Application.CreateItem(OlItemType.olAppointmentItem);
appointmentItem.MeetingStatus = OlMeetingStatus.olMeeting;
appointmentItem.RTFBody = message; // message is a byte array being passed in from elsewhere.
appointmentItem.Display(false);
The second code block will also create a new meeting request window and works in Outlook 2013, however there are a couple of subtle but important differences with the second code block...
- The created meeting request will not inherit the date and time that a user has previously clicked on in their calendar, instead it will default to the current date/time regardless of what date/time the user has clicked on in their calendar.
- The created meeting request will not respect the situation where a user is creating a meeting request "on behalf of" another user, because it ignores which calendar has been clicked on before the user initiated the new meeting request.
So my question is this: how can one now programmatically create (using a VSTO add-in) a new meeting request in Outlook 2013 that will respect which calendar the user has clicked on before hand? That is, it will satisfy the above two requirements that previously using the CommandBarControl object managed to satisfy?