Outlook.action for outlook2010 is not listing in the action menu RRS feed

  • Question

  • Hi all,

    i have done this sample piece of code in outlook 2007 in XP Machine and working fine.. but same code is not working for outlook2010 in win2003 server machine.. i am using visual studio 2010 with .net framework 4.  this code is about  outlook action for a selected item and same code i re-modified my way for my custom action. it is working fine as i said but not working in outlook2010 for server2003..

    Please help me with this...

    Please share your views... and suggest me a solution. 

    Outlook.Explorer explorer = null;
    private const string FOLDER_NAME = "Picnic";
    System.Collections.ArrayList selectedItems = new
    private void ThisAddIn_Startup(object sender,
        System.EventArgs e)
        explorer = this.Application.Explorers.Application.ActiveExplorer();
        explorer.SelectionChange += new Outlook.
    void explorer_SelectionChange()
        foreach (object selectedItem in explorer.Selection)
            Outlook.MailItem mailItem = selectedItem as Outlook.MailItem;
            if (mailItem != null)
                if (mailItem.Subject.Contains(FOLDER_NAME))
                    Outlook.Action newAction = mailItem.Actions[
                        string.Format("Copy to {0} Folder", FOLDER_NAME)];
                    if (newAction == null)
                        newAction = mailItem.Actions.Add();
                        newAction.Name = string.Format
                            ("Copy to {0} Folder", FOLDER_NAME);
                        newAction.ShowOn =
                        newAction.Enabled = true;
                    mailItem.CustomAction += new Outlook.
    void mailItem_CustomAction(object Action, object Response,
        ref bool Cancel)
            Outlook.Action mailAction = (Outlook.Action)Action;
            // Get the current selection from the explorer and 
            // copy it to the FOLDER_NAME folder 
            switch (mailAction.Name)
                case "Copy to " + FOLDER_NAME + " Folder":
                    Outlook.MailItem mailItem =
                        explorer.Selection[1] as Outlook.MailItem;
                    Outlook.MailItem mailItemCopy =
                        mailItem.Copy() as Outlook.MailItem;
                    Outlook.MAPIFolder inbox =
                    Outlook.MAPIFolder folder = null;
                    // If the folder does not exist, Create it.
                        folder = inbox.Folders[FOLDER_NAME];
                    catch (System.Runtime.InteropServices.COMException)
                        // This exception is thrown when the folder is not found.
                    catch (Exception ex)
                        throw ex;
                    if (folder == null)
                        folder = inbox.Folders.Add(FOLDER_NAME,
                    // Do not display the inspector object.
                    Cancel = true;
        catch (Exception ex)


    Sree Nunna

    • Edited by sreenunna Tuesday, June 26, 2012 10:17 AM
    • Moved by Alexander Sun Wednesday, June 27, 2012 6:43 AM Move to more appropriate forum (From:Visual C# General)
    Tuesday, June 26, 2012 9:33 AM


All replies

  • Hi Sree,

    Thanks for posting in the MSDN Forum.

    You snippet looks good. Would you please Debug it step by step, and to see where is the statement which will not work?

    Have a good day,


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

    Wednesday, June 27, 2012 6:40 AM
  • as always in office API - if you attach to some event on some object - you have to store that object somewhere so it will not get garbage collected. Here you are attaching to mailitem.CustomAction event but you are not storing mailitem anywhere, so after it might get collected right in next lopp iteration. Use List<MailItem> or some kind of wrappers as described in Ken Slovak's articles on MSDN and store that collection in static or global instance class, like ThisAddin
    Wednesday, June 27, 2012 7:16 AM
  • thanks for replying my post.. 

    i solved my issue using the below link..



    Regards, Sree Nunna.

    • Marked as answer by sreenunna Wednesday, June 27, 2012 12:58 PM
    Wednesday, June 27, 2012 12:58 PM