问题
I'm working on project which uses Outlook to perform a process when you hit an attachment with mouse's right clik.
The project was working fine till Outlook 2013. I have found this post which explains why it does not work anymore :
In Outlook 2013 they've deleted all built-in Commandbars and commandbar controls completely. For this reason you cannot access and use built-in main menus, context menus, and toolbars in Outlook 2013. The AttachmentContextMenuDisplay and ContextMenuclose events are not supported in Outlook 2013 for the same reason.
Link to the post
Indeed, my program crashed due to this event which is not triggered :
this.Application.AttachmentContextMenuDisplay += new Outlook.ApplicationEvents_11_AttachmentContextMenuDisplayEventHandler(Application_AttachmentContextMenuDisplay);
Do you guys have any idea about how to make it works for Outlook 2013 ? I'm still looking for information.
Many thanks !
回答1:
The solution was in the post I've found...
Here's the XML :
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
<contextMenus>
<contextMenu idMso="ContextMenuAttachments">
<button id="DT2MQPRContextMenuAttachments"
label="Add to MQPR..."
getVisible="DT2MQPRButton_GetVisible"
onAction="OnMyButtonClick" />
</contextMenu>
</contextMenus>
</customUI>
And the method's code :
public void OnMyButtonClick(Office.IRibbonControl control)
{
try
{
object context = control.Context;
if (context == null) return false;
if (context is Outlook.AttachmentSelection)
{
Outlook.AttachmentSelection selectedAttachments = context as Outlook.AttachmentSelection;
SelectedAttachment = attachment[1];
OutlookCommon._fName = SelectedAttachment.FileName;
// etc...
}
Marshal.ReleaseComObject(context); context = null;
}
catch (Exception ex)
{
Console.WriteLine("attachmentButton_Click " + ex.ToString());
}
}
There we go, if it could help anyone ;)
来源:https://stackoverflow.com/questions/40847152/add-attachment-context-menu-outlook-2013