简体   繁体   中英

VSTO C# - Outlook Addin - How to differ between .AttachmentSelections objects

Outlook 2010 Addin in Visual studio (C#).

I am trying to find a way to be able to tell the difference between .AttachmentSelection retrieved from Explorer (when just Previewing a mailitem on the inbox) and .AttachmentSelection retrieved from Inspector (when double clicking and actually opening the mail in a separate window), when right-clicking an attachment itself in Outlook

I'm trying to do something like:

public void ButtonClick(Office.IRibbonControl control)
{
    //right clicked attachment item -> context menu
    if (control.Context is Outlook.AttachmentSelection)
    {
        if (control.Context is Outlook.Inspector)
            MessageBox.Show("inspector");
        else if (control.Context is Outlook.Explorer)
            MessageBox.Show("explorer");
     }
}

But once the first 'if' is valid , the inner ones both fail. because the context is not Outlook Inspector, nor Outlook Explorer. Microsoft samples and explanations were not very helpfull, for in their code snippets they just messagebox the Attachments without going deeper to verifying their origin (explorer\\inspector).

My need is to grab the Mailitem, from which the user right-clicks the attachment, and extract info from it rather than going straight with the attachments.

any idea ? anyone ?

You can use the ActiveWindow method of the Application class to determine whether an attachment was opened from an Explorer or Inspector window. The method returns an object representing the current Microsoft Outlook window on the desktop, either an Explorer or an Inspector object. Returns Nothing if no Outlook explorer or inspector is open.

Also you may find the BeforeAttachmentPreview event of Outlook items helpful. It is fired before an attachment associated with an instance of the parent object is previewed. Ie the event is fired before an attachment is previewed, either from the attachment strip in the Reading Pane of the active explorer or from the active inspector. Be aware, you can cancel the operation. You just need to set the cancel parameter to true.

how about? straight from msdn

Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;
if (mailItem != null)
      {
          if (mailItem.EntryID == null)
          {
              mailItem.Subject = "This text was added by using code";
              mailItem.Body = "This text was added by using code";
          }

    }

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