简体   繁体   中英

How can my Outlook add-in get the Attachment object the user is right-clicking in my custom menu?

I want to get currently selected embedded Attachment object when right-clicking on it in context menu and clicking on custom button.

These are the steps I have done so far:

  • Added custom Button for ContextMenuInlinePicture ribbon context menu

     <customUI ...> <contextMenus> <contextMenu idMso="ContextMenuInlinePicture"> <button id="SendInlinePictureToHbbButton" label="Send to HBB" onAction="OnSendInlinePictureToHbbButtonClick" /> </contextMenu> </contextMenus> </customUI> 
  • By right clicking on it I am calling my function OnSendInlinePictureToHbbButtonClick:

      public void OnSendInlinePictureToHbbButtonClick(IRibbonControl control) { var msg = "OnSendMailToHbbButtonClick \\n\\n"; if (control.Context is Explorer) { msg = "Context=Explorer \\n"; var explorer = control.Context as Explorer; if (explorer.AttachmentSelection.Count >= 1) { msg += "AttachmentSelection \\n"; msg = explorer.AttachmentSelection .Cast<Attachment>() .Aggregate(msg, (current, attach) => current + attach.DisplayName + "\\n"); } else { var selection = explorer.Selection; msg += "MailItemSelection \\n"; if (selection.Count == 1) { var olItem = new OutlookItem(selection[1]); msg = msg + olItem.Subject + "\\n" + olItem.LastModificationTime; } else { msg = msg + "Multiple Selection Count=" + selection.Count; } } } MessageBox.Show(msg); } 
  • When running add-in, I can see custom context menu item when right clicking embedded image/attachment.

在此输入图像描述

  • After clicking on that button, above method is run, but I cannot get "AttachmentSelection". Instead I get "MailItemSelection".

在此输入图像描述

  • How I can get Attachment object user is right clicking , so I can work with it?

I have contacted Microsoft via MSDN subscription incident resolution and they told me that this cannot be done.

Attaching MS response:

Hello Martin, I am from the Messaging Developer Support team and have now taken ownership of this case. I apologise for the delay, but my team currently has a very high workload and this is affecting our response times. I've had a look at the question as described at How can my Outlook add-in get the Attachment object the user is right-clicking in my custom menu? , and the simple answer is that it is not possible to do what you want to using the Outlook Object Model. Your code is doing what is expected, as you are querying the Explorer object for its selected items – and you are having the MailItem returned. This is the selected item in the Explorer object. There are no events/properties exposed by the preview pane, so it is not possible to determine which object is selected there. It would be possible to find all the inline attachments of the currently selected item if that would be helpful, but the functionality you are after is not available. Please let me know if you would like any further information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM