none
Command Button Not Showing AttachmentContextMenuDisplay Outlook 2010 RRS feed

  • Question

  • I'm using Visual Studio 2008 to develop an Addin that is used by both Outlook 2007 and Outlook 2010 clients. My Addin works as expected in Outlook 2007 but in Outlook 2010 the AttachmentContextMenuDisplay event fires but the command buttons that I'm adding to the context menu are not visible. I'm using basically the exact same code to add menu buttons under ItemContextMenuDisplay and my code works fine there. It just doesn't work under the AttachmentContextMenuDisplay event.

    Any idea what I might be doing wrong? 
    Tuesday, October 23, 2012 3:19 AM

Answers

  • They changed how you handle context menus in Outlook 2010. You will need to fork your code depending on the version you discover at runtime. For 2010 and later you need to handle context menus in the context of Explorers and folder views by supplying ribbon XML for the Explorer.
     

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "aychekay" <=?utf-8?B?YXljaGVrYXk=?=> wrote in message news:c96d0370-0cd3-4ac5-8c14-bd6e34815224...

    I'm using Visual Studio 2008 to develop an Addin that is used by both Outlook 2007 and Outlook 2010 clients. My Addin works as expected in Outlook 2007 but in Outlook 2010 the AttachmentContextMenuDisplay event fires but the command buttons that I'm adding to the context menu are not visible. I'm using basically the exact same code to add menu buttons under ItemContextMenuDisplay and my code works fine there. It just doesn't work under the AttachmentContextMenuDisplay event.

    Any idea what I might be doing wrong? 

    Ken Slovak MVP - Outlook
    • Marked as answer by villagemedia Tuesday, December 4, 2012 4:27 PM
    Tuesday, October 23, 2012 1:13 PM

All replies

  • They changed how you handle context menus in Outlook 2010. You will need to fork your code depending on the version you discover at runtime. For 2010 and later you need to handle context menus in the context of Explorers and folder views by supplying ribbon XML for the Explorer.
     

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "aychekay" <=?utf-8?B?YXljaGVrYXk=?=> wrote in message news:c96d0370-0cd3-4ac5-8c14-bd6e34815224...

    I'm using Visual Studio 2008 to develop an Addin that is used by both Outlook 2007 and Outlook 2010 clients. My Addin works as expected in Outlook 2007 but in Outlook 2010 the AttachmentContextMenuDisplay event fires but the command buttons that I'm adding to the context menu are not visible. I'm using basically the exact same code to add menu buttons under ItemContextMenuDisplay and my code works fine there. It just doesn't work under the AttachmentContextMenuDisplay event.

    Any idea what I might be doing wrong? 

    Ken Slovak MVP - Outlook
    • Marked as answer by villagemedia Tuesday, December 4, 2012 4:27 PM
    Tuesday, October 23, 2012 1:13 PM
  • Thanks for our reply Ken. I have successfully written additional code to create (and handle) the right-click menus for attachments in Outlook 2010.

    It appears, so far, that I haven't actually had to do any forking. The code for 2007 simply fails to run in 2010 and vice versa. Neither of these failures produce any error messages.

    One of the problems I ran into was figuring out how to get to the Attachment when they did click on my right-click button. For the convenience of anyone else trying to figure this out, here it is in VB.Net. This is the code for my button's CallBack function contained inside MyRibbonXML.vb file.

    Public Sub btnMyRibbonButton_Click(ByVal control As Office.IRibbonControl)        
    	Dim atts = TryCast(insp.CurrentItem, control.Context)
    	If atts IsNot Nothing Then
    		MsgBox(atts.Count)
    	End If
    End Sub


    • Edited by villagemedia Tuesday, October 23, 2012 6:29 PM code was incorrect
    Tuesday, October 23, 2012 2:45 PM
  • Hi aychekay,

    Thanks for posting in the MSDN Forum.

    It seems that you have error in syntax “Dim atts = TryCast(insp.CurrentItem, control.Context)” and I will provide you my snippet for your issue. I hope it can help you:

        Public Sub Execute1(ByVal Control As Office.IRibbonControl)
            Dim olApp As Outlook.Application = Globals.ThisAddIn.Application
            Dim olMail As Outlook.MailItem = olApp.ActiveInspector().CurrentItem
    
            For Each Item As Outlook.Attachment In olMail.Attachments
                If Item.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x37140003") = 0 Then
                    MsgBox(Item.FileName)
                End If
            Next
        End Sub

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Friday, October 26, 2012 6:06 AM
    Moderator
  • Hi aychekay,

    How did you get to show the button on the menu? I still couldn't figure it out. I am new to Addin programming but have long enough knowledge of c#.

    Also, do you know how would this event in the case of compose mail?

    Som


    Tuesday, December 4, 2012 10:42 AM