none
Outlook 2007 Add-in Assignment RRS feed

  • Question

  • I'm really new at add-in stuff. My code should do these: An outlook user saves/creates anything. If the created item is an appointment item my system must save it under the c: directory, taking the item subject as file name. Here is my code. What is wrong there?

    When I create a new appointment the if clause is working, if I write there any other code, it is working, but I can't get the ai's info, such as ai.Subject. So I think the problem is on

                Outlook.AppointmentItem ai = Item as Outlook.AppointmentItem;

    line. I suppose this is assignment is not working(the instance is not created), but why I really don't know. What I can do to fix this?

    namespace SendToMRBS
    {
        public partial class ThisAddIn
        {
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
               this.Application.ItemLoad += new Outlook.ApplicationEvents_11_ItemLoadEventHandler(Application_ItemLoad);
            }
    
        void Application_ItemLoad(object Item)
        {
            if (Item is Outlook.AppointmentItem)
            {
                Outlook.AppointmentItem ai = Item as Outlook.AppointmentItem;
                ai.SaveAs("C:\\" + ai.Subject, Microsoft.Office.Interop.Outlook.OlSaveAsType.olICal);
            }
        }
    
    
        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
    
    }
    

    Background: Outlook 2007 VS2010 C#


    Monday, May 7, 2012 6:03 AM

Answers

  • The ItemLoad event is somewhat useless; you can’t access anything but the Item.Class and Item.MessageClass properties, nor can you cast it to a hard object reference.  The best way to capture anything that is opened is to trap the Inspectors.NewInspector event.


    Eric Legault
    MVP (Outlook)
    About me...

    Monday, May 7, 2012 2:22 PM
    Moderator

All replies

  • The ItemLoad event is somewhat useless; you can’t access anything but the Item.Class and Item.MessageClass properties, nor can you cast it to a hard object reference.  The best way to capture anything that is opened is to trap the Inspectors.NewInspector event.


    Eric Legault
    MVP (Outlook)
    About me...

    Monday, May 7, 2012 2:22 PM
    Moderator
  • But nothing will be open. The thing, I'm trying to do is that when a user creates a new appointment or edits an existing appointment, the .ics file of the appointment item must be saved automatically. Can I do that with the assistance of Inspectors?
    Tuesday, May 8, 2012 5:34 AM
  • of course something will be opened - when user creates new item or edits existing new window is opened for that operation in outlook. Those windows for reading/editing items are called inspectors. Follow Eric's advice and you should be able to achieve your goal.
    Tuesday, May 8, 2012 8:48 AM
  • I get that. NewInspector worked perfectly, after a little modification. Thank you for your concern.
    Tuesday, May 8, 2012 2:50 PM
  • FYI, users can also edit items in certain folder views without opening them.  In these cases you have to monitor the Explorer.SelectionChange event to get a handle to the item.

    Eric Legault
    MVP (Outlook)
    About me...

    Tuesday, May 8, 2012 3:09 PM
    Moderator
  • Many thanks for this extra information, I will be in need of that.
    Wednesday, May 9, 2012 5:52 AM