none
Custom Action for COM Add-in RRS feed

  • Question

  • Hello,

    I've made an Addin that allows me to clear the registry key that governs the 'Room' list in the appointment window. I've tested and seems to work fine on Startup, however i would like to run this as rule after sending an appointment email.

    I can't seem to find any good explanation on how to convert this add-in to make it appear in the custom action list of the 'Create Rules' part of outlook.

    Any help would be greatly appreciated.

    Thanks!

    jack

    namespace Clear_Rooms

    {
        public partial class ThisAddIn
        {
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                try
                {
                    RegistryKey myKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Office\\14.0\\Outlook\\Preferences", true);
                    // System.Diagnostics.Debug.WriteLine("Test key: {0}", myKey);
                    string x = (string)myKey.GetValue("LocationMRU");
                    if (!String.IsNullOrEmpty(x))
                    {
                        myKey.DeleteValue("LocationMRU");
                        myKey.Close();
                    }
                    MessageBox.Show("Double Checking Prints", "Seriously");
                }
                catch
                {
                    MessageBox.Show("Exception in Room Clear Add-in", "Seriously");
                }
            }

            private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
            {
            }

            #region VSTO generated code

            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InternalStartup()
            {
                this.Startup += new System.EventHandler(ThisAddIn_Startup);
                this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
            }

            #endregion
        }
    }

            
    Thursday, August 20, 2015 2:56 AM

Answers

  • Why do you want to make it a custom action? Process the Application.ItemSend event, check that the item being sent is an instance of the MeetingItem object, and do what you need to do.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by Jack OHara Thursday, August 20, 2015 7:52 PM
    Thursday, August 20, 2015 3:26 AM
  • Hello Jack,

    When exactly do you need to run the code?

    The ItemSend event of the Application class is fired whenever an Microsoft Outlook item is sent, either by the user through an Inspector (before the inspector is closed, but after the user clicks theSend button) or when the Send method for an Outlook item, such as MailItem, is used in a program.

    The SyncEnd event of the SyncObject class is fired immediately after Microsoft Outlook finishes synchronizing a user’s folders using the specified Send/Receive group.

    Why do you need to add the add-in stuff to the the custom action list of the 'Create Rules' part of outlook? Add-ins are independent things, they can keep their own settings.

    • Marked as answer by Jack OHara Thursday, August 20, 2015 7:52 PM
    Thursday, August 20, 2015 5:12 AM

All replies

  • Why do you want to make it a custom action? Process the Application.ItemSend event, check that the item being sent is an instance of the MeetingItem object, and do what you need to do.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by Jack OHara Thursday, August 20, 2015 7:52 PM
    Thursday, August 20, 2015 3:26 AM
  • Hello Jack,

    When exactly do you need to run the code?

    The ItemSend event of the Application class is fired whenever an Microsoft Outlook item is sent, either by the user through an Inspector (before the inspector is closed, but after the user clicks theSend button) or when the Send method for an Outlook item, such as MailItem, is used in a program.

    The SyncEnd event of the SyncObject class is fired immediately after Microsoft Outlook finishes synchronizing a user’s folders using the specified Send/Receive group.

    Why do you need to add the add-in stuff to the the custom action list of the 'Create Rules' part of outlook? Add-ins are independent things, they can keep their own settings.

    • Marked as answer by Jack OHara Thursday, August 20, 2015 7:52 PM
    Thursday, August 20, 2015 5:12 AM
  • @Dmitry and Eugene thanks for your help!

    Making it a custom action was mainly out of ignorance (I'm a Producer dabbling in code, please forgive)

    After some googling i found the event you mentioned so added the event handler (below)

    The only bug left is that the event seems to be processed when the button is pressed. So right now i clear the registry key on the button press, then outlook readds it with latest. So i need to find out how to make the event non-blocking or asynchronous.

    Thanks again.

    Jack

    namespace Clear_Rooms
    {
        public partial class ThisAddIn
        {
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                this.Application.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(this.Application_ItemSend);
            }

            private void Application_ItemSend(object Item, ref bool Cancel)
            {
                try
                {
                    RegistryKey myKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Office\\14.0\\Outlook\\Preferences", true);
                    // System.Diagnostics.Debug.WriteLine("Test key: {0}", myKey);
                    String value = Convert.ToString(myKey.GetValue("LocationMRU"));
                    // System.Diagnostics.Debug.WriteLine("Test key: {0}", value);
                    if (!String.IsNullOrEmpty(value))
                    {
                        myKey.DeleteValue("LocationMRU");
                        myKey.Close();
                    }
                    // MessageBox.Show("Double Checking Prints", "Seriously");
                }
                catch
                {
                    MessageBox.Show("Exception in Room Clear Add-in", "Seriously");
                }
            }


    Thursday, August 20, 2015 7:21 PM
  • I am not sure I understand why you want to make the code above asynchronous - does it take a long time to execute? You are just deleting s single registry value...

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, August 20, 2015 11:38 PM
  • Hey Dmitry

    Mainly because it seems the ItemSend event happens when the user hits the 'Send' button, and outlook then creates\edits the registry key after that event.

    So right now my program clear the registry key on the hit of the send button, then re-creates the registry key with the new value straight afterwards,

    Thanks,

    Jack

    Tuesday, August 25, 2015 12:20 AM
  • Try to use the Items.ItemAdd event on the Sent Items folder - it will fire after the item is sent and moved to the Sent Items folder.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Tuesday, August 25, 2015 1:43 AM