none
Problem using contextmenus for attachments in Outlook 2010 RRS feed

  • Question

  • Hi

    I have looked around a lot for an answer on how the contextmenus is designed and ment to be used in Outlook 2010.

    I have a fully working Add-In för Outlook 2007, in which I add a CommandBarButton in the contextmenu displayed when the user right-clicks an attachment in an opened mailitem. This seems to be impossible to achieve in Outlook 2010.

    In scenario 1 I just reused the code from my convertred VS2008 to VS2010 solution, in which I use the Application_AttachmentContextMenuDisplay event handler to add a commandbarbutton to the passed CommandBar object.
    The button is added without errors in the code, but no button is displayed in the context menu.
    When I loop through the items in the CommandBar they don't fully match what I see in the menu. The spelling differs from some of them aswell as the number of Items. It looks like the event passes the wrong Commandbar as a parameter, which then must be a bug in Outlook.

    In scenario 2 I tried to use the new Ribbon XML interface, which I use a lot in my other Office Add-Ins.
    But when I use the code below, the menu is only displayed when I right-click the attachment in the Preview-pane, not when the mailitem is opened up.

    <?xml version="1.0" encoding="iso-8859-1"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_OnLoad" loadImage="LoadImage">
      <ribbon startFromScratch="false">
      </ribbon>
      <contextMenus>
        <contextMenu idMso="ContextMenuAttachements">
          <button id="theAttachments" label="Show metadata" getEnabled="GetStatus" onAction="OnActionButton"/>
        </contextMenu>
      </contextMenus>
    </customUI>

    I have read through the excel documents Office2010ControlIDs from Microsoft and couldn't found another idMso to use for the contextmenu in an opened mailitem attachments.

    Have I missed something here?

    Thanks in advance


    Best Regards Peter Karlström Midrange AB, Sweden

    Monday, February 27, 2012 3:13 PM

Answers

  • It works here.
     
    I tested in a VS 2010 VSTO 4 addin running on Windows 7 and Outlook 2010 x86. The only changes I made were to eliminate the onAction callback as I didn't want to bother coding it, and I changed getEnabled to enabled='true'.
     
    I supplied the XML when GetCustomUI() was called with Case "Microsoft.Outlook.Mail.Read". When I right-clicked on an attachment in a sent item I got the "Kontrollera/Visa metadata" button in the context menu.
     
    Do you have the setting in Outlook turned on to display user interface errors? If an error is being detected that would at least show you the error message.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Peter Karlström" <=?utf-8?B?UGV0ZXIgS2FybHN0csO2bQ==?=> wrote in message news:89782e42-ca6d-49b6-8740-3379a0f02ba4...

    Hi Ken

    Thanks for replying.

    Sorry for the typo! The code is correct, the code in the post was partly handwritten, not pasted.

    The correct, used and nonfunctioning XML is:

    <?xml version='1.0' encoding='iso-8859-1'?>
    <customUI xmlns='http://schemas.microsoft.com/office/2009/07/customui' onLoad='Ribbon_OnLoad' loadImage='LoadImage'>
      <ribbon startFromScratch='false'>
      </ribbon>
      <contextMenus>
        <contextMenu idMso='ContextMenuAttachments'>
          <button id='theAttachments' label='Kontrollera/Visa metadata' getEnabled='GetStatus' onAction='OnActionButton'/>
        </contextMenu>
      </contextMenus>
    </customUI>

    So, does this XML work for you from an opened mailitem?


    Best Regards Peter Karlström Midrange AB, Sweden



    Ken Slovak MVP - Outlook
    Monday, February 27, 2012 6:41 PM
  • Hi Peter,

    Thanks for the help it worked

    Regards

    Steve

    Tuesday, May 28, 2013 8:47 AM

All replies

  • The MailItemRead XML has ContextMenuAttachments, but without the "e" you added:
     
    <contextMenu idMso="ContextMenuAttachements">
    <contextMenu idMso="ContextMenuAttachments">
    Does that work any better for you?
     
    As far as using the older Application context menu events, those are now deprecated and shouldn't be used for Outlook 2010 code.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Peter Karlström" <=?utf-8?B?UGV0ZXIgS2FybHN0csO2bQ==?=> wrote in message news:f49be5ea-fb40-4a2a-94c4-3dd51b2875a2...

    Hi

    I have looked around a lot for an answer on how the contextmenus is designed and ment to be used in Outlook 2010.

    I have a fully working Add-In för Outlook 2007, in which I add a CommandBarButton in the contextmenu displayed when the user right-clicks an attachment in an opened mailitem. This seems to be impossible to achieve in Outlook 2010.

    In scenario 1 I just reused the code from my convertred VS2008 to VS2010 solution, in which I use the Application_AttachmentContextMenuDisplay event handler to add a commandbarbutton to the passed CommandBar object.
    The button is added without errors in the code, but no button is displayed in the context menu.
    When I loop through the items in the CommandBar they don't fully match what I see in the menu. The spelling differs from some of them aswell as the number of Items. It looks like the event passes the wrong Commandbar as a parameter, which then must be a bug in Outlook.

    In scenario 2 I tried to use the new Ribbon XML interface, which I use a lot in my other Office Add-Ins.
    But when I use the code below, the menu is only displayed when I right-click the attachment in the Preview-pane, not when the mailitem is opened up.

    <?xml version="1.0" encoding="iso-8859-1"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_OnLoad" loadImage="LoadImage">
      <ribbon startFromScratch="false">
      </ribbon>
      <contextMenus>
        <contextMenu idMso="ContextMenuAttachements">
          <button id="theAttachments" label="Show metadata" getEnabled="GetStatus" onAction="OnActionButton"/>
        </contextMenu>
      </contextMenus>
    </customUI>

    I have read through the excel documents Office2010ControlIDs from Microsoft and couldn't found another idMso to use for the contextmenu in an opened mailitem attachments.

    Have I missed something here?

    Thanks in advance


    Best Regards Peter Karlström Midrange AB, Sweden


    Ken Slovak MVP - Outlook
    Monday, February 27, 2012 3:57 PM
  • Hi Ken

    Thanks for replying.

    Sorry for the typo! The code is correct, the code in the post was partly handwritten, not pasted.

    The correct, used and nonfunctioning XML is:

    <?xml version='1.0' encoding='iso-8859-1'?>
    <customUI xmlns='http://schemas.microsoft.com/office/2009/07/customui' onLoad='Ribbon_OnLoad' loadImage='LoadImage'>
      <ribbon startFromScratch='false'>
      </ribbon>
      <contextMenus>
        <contextMenu idMso='ContextMenuAttachments'>
          <button id='theAttachments' label='Kontrollera/Visa metadata' getEnabled='GetStatus' onAction='OnActionButton'/>
        </contextMenu>
      </contextMenus>
    </customUI>

    So, does this XML work for you from an opened mailitem?


    Best Regards Peter Karlström Midrange AB, Sweden


    Monday, February 27, 2012 4:37 PM
  • I haven't tried that context menu yet in 2010, I've had no call for it in any of my own applications. I'll give it a shot in a test addin and let you know if I get it working.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Peter Karlström" <=?utf-8?B?UGV0ZXIgS2FybHN0csO2bQ==?=> wrote in message news:89782e42-ca6d-49b6-8740-3379a0f02ba4...

    Hi Ken

    Thanks for replying.

    Sorry for the typo! The code is correct, the code in the post was partly handwritten, not pasted.

    The correct, used and nonfunctioning XML is:

    <?xml version='1.0' encoding='iso-8859-1'?>
    <customUI xmlns='http://schemas.microsoft.com/office/2009/07/customui' onLoad='Ribbon_OnLoad' loadImage='LoadImage'>
      <ribbon startFromScratch='false'>
      </ribbon>
      <contextMenus>
        <contextMenu idMso='ContextMenuAttachments'>
          <button id='theAttachments' label='Kontrollera/Visa metadata' getEnabled='GetStatus' onAction='OnActionButton'/>
        </contextMenu>
      </contextMenus>
    </customUI>

    So, does this XML work for you from an opened mailitem?


    Best Regards Peter Karlström Midrange AB, Sweden



    Ken Slovak MVP - Outlook
    Monday, February 27, 2012 5:04 PM
  • It works here.
     
    I tested in a VS 2010 VSTO 4 addin running on Windows 7 and Outlook 2010 x86. The only changes I made were to eliminate the onAction callback as I didn't want to bother coding it, and I changed getEnabled to enabled='true'.
     
    I supplied the XML when GetCustomUI() was called with Case "Microsoft.Outlook.Mail.Read". When I right-clicked on an attachment in a sent item I got the "Kontrollera/Visa metadata" button in the context menu.
     
    Do you have the setting in Outlook turned on to display user interface errors? If an error is being detected that would at least show you the error message.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Peter Karlström" <=?utf-8?B?UGV0ZXIgS2FybHN0csO2bQ==?=> wrote in message news:89782e42-ca6d-49b6-8740-3379a0f02ba4...

    Hi Ken

    Thanks for replying.

    Sorry for the typo! The code is correct, the code in the post was partly handwritten, not pasted.

    The correct, used and nonfunctioning XML is:

    <?xml version='1.0' encoding='iso-8859-1'?>
    <customUI xmlns='http://schemas.microsoft.com/office/2009/07/customui' onLoad='Ribbon_OnLoad' loadImage='LoadImage'>
      <ribbon startFromScratch='false'>
      </ribbon>
      <contextMenus>
        <contextMenu idMso='ContextMenuAttachments'>
          <button id='theAttachments' label='Kontrollera/Visa metadata' getEnabled='GetStatus' onAction='OnActionButton'/>
        </contextMenu>
      </contextMenus>
    </customUI>

    So, does this XML work for you from an opened mailitem?


    Best Regards Peter Karlström Midrange AB, Sweden



    Ken Slovak MVP - Outlook
    Monday, February 27, 2012 6:41 PM
  • Hi Ken

    Thanks for your quick replies.

    The environment which will be used at my customers is Swedish Windows 7 64-bit, Swedish Office 2010 32-bit.
    My Add-In is created with VS2010 and .NET Framework 3.51.(since this is only converted from VS2008 and Office 2007)

    The Ribbon Interface is attached correctly and no errors are shown,(The Show interface errors flag are checked).
    The context menu "ContextMenuAttachments" only seems to attach to the previewpanes context menu, and in this menu all works well.

    It seemed like I missed something obvious.

    So I created a new Add-In from scratch and moved the small part of funtionality from the original solution. Voila!

    I don't know exactly what was wrong, but I've learned not to trust converters fully.

    Thanks Ken for your support.


    Best Regards Peter Karlström Midrange AB, Sweden

    Tuesday, February 28, 2012 9:16 AM
  • Hi Peter is there any chance you could make available online a project that adds a context menu on both Preview pane and the Independent Window of the email. I tried to do  as you did but I did not manage to get it to work for the Independent Email window.

    Regards

    Steve

    Monday, May 27, 2013 2:25 PM
  • Hi

    Can't make the project public, but I'll explain what you have to do in your code.

    In your GetcustomUI-function you check for more than one RibbonIDs,
    like this:

        Public Function GetCustomUI(ByVal ribbonID As String) As String Implements Office.IRibbonExtensibility.GetCustomUI
    
            Dim ribID As String
            Dim ribsID As String = ""
    
            ribsID = 1
    
            Select Case ribbonID
                Case "Microsoft.Outlook.Mail.Read"
                    GetCustomUI = GetRibbonXML(ribID)
                Case "Microsoft.Outlook.Explorer"
                    GetCustomUI = GetRibbonXML(ribID)
                Case Else
                    GetCustomUI = ""
            End Select
    
        End Function
    

    The Ribbon XML is read from a database, but as you see, the same XML-code is used for the two different Ribbons, and the XML looks as my (correctly spelled) sample above.

    Please Mark this as Answer ig you succeed.

     

    Best Regards Peter Karlström Midrange AB, Sweden

    • Proposed as answer by Fairmutex Tuesday, May 28, 2013 8:46 AM
    Monday, May 27, 2013 3:20 PM
  • Hi Peter,

    Thanks for the help it worked

    Regards

    Steve

    Tuesday, May 28, 2013 8:47 AM