none
Outlook2013 Email address's context menu RRS feed

  • Question

  • I have developed an add-in of Outlook by using VS2010 and all of functions can work normally in the Outlook2010 and 2013, except one, using Outlok2013, creating a new Meeting, in this GUI, when I input an Email Address which type is "Office.MsoContactCardAddressType.msoContactCardAddressTypeOutlook". when I right-click it, the code "object o = ae.Selection[1];" will be executed, sometimes, this sentence is OK, sometimes, an error occur, Sometimes, it will return a wrong value(other contact's Email.). I have used the same action to debug it.

    anyway, "Microsoft.Office.Interop.Outlook.AddressEntry addr = Globals.ThisAddIn.Application.Session.GetAddressEntryFromID(card.Address);", when execute this code, an error always happen.

    Is it a bug of Outlook or I used wrong method??

    Thank you.
    Sunday, January 13, 2013 8:03 AM

All replies

  • Hi richar1980,

    Thanks for posting in the MSDN Forum.

    Would you please show me the details for the exception for further research?

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, January 15, 2013 5:16 AM
    Moderator
  • Tom,

    Thanks for your reply.

    1. object o = ae.Selection[1];
    when Outlook2013 execute this sentence, the message is "Array index out of bounds." it seems that there is no item has been selected.

    2. Microsoft.Office.Interop.Outlook.AddressEntry addr = Globals.ThisAddIn.Application.Session.GetAddressEntryFromID(card.Address);

    when Outlook2013 execute this sentence, the message is "The attempted operation failed.  An object could not be found."

    3. operation flow

    Outlook2013 click "Calendar", opening Calendar Explorer, Clicking the menu item "New Meeting", opening "Meeting Explorer", in this GUI, click the button "To" and select a contact and click the button "OK", then, right-click the Email address of this contact in the "Meeting Explorer", Outlook will call my event defined in my Addin class. in this event, it will execute the above sentences.

    I found that the below sentences can execute normally at anywhere include Outlook2010, but when you operate it like the above flow, an error will occur. and sometimes, it will return a wrong value(other contact's Email.), like I said before.

    So I guess it is a bug of Outlook2013. I used the version of Outlook is 15.0.0.4128

    Best Regards.
    Tuesday, January 15, 2013 1:20 PM
  • Hi richar1980,

     1. object o = ae.Selection[1];
    when Outlook2013 execute this sentence, the message is "Array index out of bounds." it seems that there is no item has been selected.

    Do you ensure that you have selected something? This exception only occur when nothing has been selected in explorer.

     2. Microsoft.Office.Interop.Outlook.AddressEntry addr = Globals.ThisAddIn.Application.Session.GetAddressEntryFromID(card.Address);

    when Outlook2013 execute this sentence, the message is "The attempted operation failed.  An object could not be found."

    As far as I known that EntryID is similar with GUID. I would recommend you confirm card.Address point to a EntryID instead of a real address of contacts.

    And I would recommend you post detailed code for your event for further research. And include subscribers for this event will helper us to trouble shoot it.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, January 16, 2013 6:23 AM
    Moderator
  • > Do you ensure that you have selected something? This exception only occur when nothing has been selected in explorer.

    Yes. I am sure.

    > As far as I known that EntryID is similar with GUID. I would recommend you confirm card.Address point to a EntryID instead of a real address of contacts.

    Yes. it looks like a GUID and its AddressType is "Office.MsoContactCardAddressType.msoContactCardAddressTypeOutlook"

    Below code the part of my code, will be called in the event 

    <button id="MyContextMenuMailHeaderRecipientSendIM"             
                  getVisible="OnVisiable"/>

               void OnVisiable(...)

    {

                card = (Office.IMsoContactCard)pControl.Context;
                if (card.AddressType == Office.MsoContactCardAddressType.msoContactCardAddressTypeOutlook)
                {
                    try
                    {
                        if (version.StartsWith("15"))
                        {
                            Microsoft.Office.Interop.Outlook.Explorer ae = Globals.ThisAddIn.Application.ActiveExplorer();
                                
                            object o = ae.Selection[1]; // an error will occur
                            if (o is Microsoft.Office.Interop.Outlook.ContactItem)
                            {
                                
                                return;
                            }
                        }
                    }
                    catch { }

                    Microsoft.Office.Interop.Outlook.AddressEntry addr = Globals.ThisAddIn.Application.Session.GetAddressEntryFromID(card.Address); // an errror will occur.
                    Microsoft.Office.Interop.Outlook.ContactItem item = addr.GetContact();
                    
                    ......
                }
                else if (card.AddressType == Office.MsoContactCardAddressType.msoContactCardAddressTypeSMTP)

    .......

    }

    Wednesday, January 16, 2013 7:19 AM
  • Tom,

    The part of code is appended for Outlook2013, Because Outlook2013 is different.

    So, If my code is wrong or it is the issue of Outlook2013?? Could you tell me.

    Thank you.

    Thursday, January 17, 2013 5:01 AM
  • Hi richar1980,

    There still have some problem need clarify:

    1. as getVisible, you need a function like that "public bool MyFunction(Office.IRibbonControl Control)". Your code looks doesn't make sense.
    2. I need more complete RibbonX for trouble shooting.
    3. For the first question which I mentioned yesterday, would you please tell me which kind of explorer model your use when the code execute? For example if you select an Item in Mail model then your switch your model to Calendar and execute your code there will get the exception which you mentioned. If you switch back to Mail model all works fine.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, January 17, 2013 6:21 AM
    Moderator
  • Tom,

    Thanks for your replay.

    > as getVisible, you need a function like that "public bool MyFunction(Office.IRibbonControl Control)". Your code >looks doesn't make sense.

    My function definition is the same as yours.

    It does not matter with Mail model, just Meeting model.

    1. In the main window of Outlook2013, Clicking the buttong Calendar.

    2. In the Calendar model, Clicking the menu item "New Meeting", opening Meeting model, then, click “To” button in Meeting model and select contact and click the button OK, then, the Email address of this contact will be added into the textbox of “To“ in the Meeting model, at this time, when you right-click the Email address, the event of getVisible will be called and you can trace the code, when the code execute the sentence which I have mentioned, the error will happen.

    Best Regards.


    • Edited by richar1980 Thursday, January 17, 2013 11:06 AM
    Thursday, January 17, 2013 10:52 AM
  • Hi richar1980,

     In the Calendar model, Clicking the menu item "New Meeting", opening Meeting model, then, click “To” button in Meeting model and select contact and click the button OK, then, the Email address of this contact will be added into the textbox of  “To“ in the Meeting model, at this time, when you right-click the Email address, the event of getVisible will be called and you can trace the code, when the code execute the sentence which I have mentioned, the error will happen.

    It just what I worry about , as far as I know that calendar model will not have selected item by default. I would recommend you reproduce your process after you select a exist appointment item. Let's see whether out of range exception will raise again.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Friday, January 18, 2013 6:48 AM
    Moderator
  • Tom,

    Thanks for your reply.

    ...............................

    public bool OnVisiable(Office.IRibbonControl pControl)

    {

    ...

    card = (Office.IMsoContactCard)pControl.Context;

    card.Address

    ...

    }

    ...............................

    As you know, if the Email Type is "Office.MsoContactCardAddressType.msoContactCardAddressTypeSMTP", the variable "card.Address" is an available Email address. at this situation, my process is OK.

    But if the Email Type is "Office.MsoContactCardAddressType.msoContactCardAddressTypeOutlook", the variable "card.Address" is saved an ID like GUID. My requirement is get its Email address and the information of this ContactItem, like FullName etc. So I need to call the interface to get ContactItem by using this ID. Now, I used "Globals.ThisAddIn.Application.Session.GetAddressEntryFromID" to get "Microsoft.Office.Interop.Outlook.AddressEntry",  But as I said before, when I use Outlook2013 to execute this interface, an error happen, So I attempt to use "ActiveExplorer" and "Selection[1]" to get this ContactItem, but it still fail, and I attempted to call MAPI to get it. But I can not find a member variable to compare with this GUID.

    Could you help me which API I should use and get the ContactItem by using the ID of Email??

    Thank you very much.

    Friday, January 18, 2013 8:31 AM
  • Hi richar1980,

    Would you please show me integral ribbon xml for further research?

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, January 21, 2013 8:03 AM
    Moderator
  • Tom,
    you can see below code.

    // This method will be called by Outlook.
    public string GetCustomUI(string ribbonID)
    {
        switch (ribbonID)
        {
            case "Microsoft.Outlook.Explorer":
                return GetResourceText

    ("ContactMenuConnected.xml");

            case "Microsoft.Mso.IMLayerUI":
                return GetResourceText("ContactMenu.xml");

            default:
                return string.Empty;
        }
    }

    // ContactMenuConnected.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui"

    onLoad="Ribbon_Load">
    <ribbon>
    <tabs>
        <tab idMso="TabAddIns" label="MyAddin">
        <group id="MyGroup"
                label="MyGroup">
            <button id="MyButton"
                    size="large"
                    label="Connected"
                    imageMso="HappyFace"
                    onAction="OnMyButtonClick"/>
        </group>
        </tab>
    </tabs>
    </ribbon>

    <contextMenus>
    <contextMenu idMso="ContextMenuContactItem">
        <button id="MyContextMenuContactCardRecipientMC"
                getLabel="OnGetLabel"
                getVisible="OnVisiable"
                onAction="OnMCClick"/>
        <button id="MyContextMenuContactCardRecipientSIM"
                getLabel="OnGetLabel"
                getVisible="OnVisiable"
                onAction="OnSIMClick"/>
    </contextMenu>
    </contextMenus>

    </customUI>

    // ContactMenu.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui"

    onLoad="Ribbon_Load">
      <contextMenus>
        <contextMenu idMso="ContextMenuContactCardRecipient">
          <button id="MyContextMenuMailHeaderRecipientMC"
                  getLabel="OnGetLabel"
                  onAction="OnMCClick"
                  getVisible="OnVisiable"/>
          <button id="MyContextMenuMailHeaderRecipientSIM"
                  getLabel="OnGetLabel"
                  onAction="OnSIMClick"
                  getVisible="OnVisiable"/>
        </contextMenu>
      </contextMenus>
    </customUI>
    • Edited by richar1980 Tuesday, January 29, 2013 8:37 AM
    Wednesday, January 23, 2013 7:42 AM
  • Hi richar1980,

    I noticed a detailed that we can create a new meet request if you have selected an appointment item which already existed. So I suppose that hasn't selected any appointment item when you create a new meeting request. When I tried your code via following steps:

    1. switch to Calendar view.
    2. create a new meeting item.
    3. fill a contract to "To" field.
    4. switch back to explorer and select a appointment item.
    5. switch back to compose meeting item and right click on contract which populate in To field.

    All works fine on my side, no exception raise.

    I would recommend you try it.

    Hope it can help you.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, January 25, 2013 5:42 AM
    Moderator
  • Tom,

    thank you.

    If your mean is that enter a email address into the To field and after outlook recognise it as a contact, right click on the contact, all works fine?? If so, it is ok too on  my side.

    But if you click the button To at  the meeting item, you can see a dialog, in this dialog, you can select a contact and Outlook will fill it into the To field automatically instead of entering the Email by using manually. If using this method, when you right click on the contact, when the code execute the method I have mentioned, the exception raise.

    Have a good day.

    Tuesday, January 29, 2013 5:35 AM
  • Right-clicking on something does not select that object. If there was no selection previously there will be none after a right-click. A right-click on something other than what's selected will open a context menu for whatever was right-clicked and not necessarily what was selected, if anything.
     
    When you work with the Selection collection you must always be prepared to find Selection.Count = 0.
     
    Address is not an EntryID, it would be expected to get an error with the code you're using. You are using the GetAddressEntryFromID() method incorrectly.
     
    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "richar1980" <=?utf-8?B?cmljaGFyMTk4MA==?=> wrote in message news:de451970-6651-46d7-b0cc-aa643bbd26df...
    I have developed an add-in of Outlook by using VS2010 and all of functions can work normally in the Outlook2010 and 2013, except one, using Outlok2013, creating a new Meeting, in this GUI, when I input an Email Address which type is "Office.MsoContactCardAddressType.msoContactCardAddressTypeOutlook". when I right-click it, the code "object o = ae.Selection[1];" will be executed, sometimes, this sentence is OK, sometimes, an error occur, Sometimes, it will return a wrong value(other contact's Email.). I have used the same action to debug it.

    anyway, "Microsoft.Office.Interop.Outlook.AddressEntry addr = Globals.ThisAddIn.Application.Session.GetAddressEntryFromID(card.Address);", when execute this code, an error always happen.

    Is it a bug of Outlook or I used wrong method??

    Thank you.

    Ken Slovak MVP - Outlook
    Wednesday, February 6, 2013 5:49 PM
    Moderator