问题
When right clicking on a calendar and running a ribbon action is it possible to get the selected calendar date the same way you would get the current mailItem or appointmentItem?
Ribbon XML:
<contextMenu idMso="ContextMenuCalendarView">
<menu id="CallenderMenu" label="Actions">
<button id="NewDiaryEvent" label="Create new" onAction="CreateCallenderItem_click" />
</menu>
</contextMenu>
C#:
public void CreateCallenderItem_click(IRibbonControl control)
{
// Get selected calendar date
}
回答1:
Dmitry is correct but here is an example of the code I have used to get the start and finish date of the area you have selected:
public void CreateCallenderItem_click(IRibbonControl control)
{
// Get selected calendar date
Outlook.Application application = new Outlook.Application();
Outlook.Explorer explorer = application.ActiveExplorer();
Outlook.Folder folder = explorer.CurrentFolder as Outlook.Folder;
Outlook.View view = explorer.CurrentView as Outlook.View;
if (view.ViewType == Outlook.OlViewType.olCalendarView)
{
Outlook.CalendarView calView = view as Outlook.CalendarView;
DateTime calDateStart = calView.SelectedStartTime;
DateTime calDateEnd = calView.SelectedEndTime;
// Do stuff with dates.
}
}
I hope this helps you some more.
回答2:
Read Application.ActiveExplorer.CuurentFolder.CurrentView property, check if it is CalendarView, then read the CalendarView.SelectedStartTime property.
来源:https://stackoverflow.com/questions/25040715/outlook-addin-get-current-selected-calendar-date