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?