1
votes

I'm trying to create a Outlook 2013 AddIn and I have some troubles accessing the properties of the AppointmentItem. Afterwards you find a shortened example code:

    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)
        {
            try
            {
                    appointmentItem = Item as Outlook.AppointmentItem;

                    string sub = appointmentItem.Subject; // <--------
    ...

The problem ist, that I'cannot access the properties of the appintment because the data is not yet available for the memory:

MSDN: ApplicationEvents_11_Event.ItemLoad event: This event occurs when the Outlook item begins to load into memory. Data for the item is not yet available, other than the values for the Class and MessageClass properties of the Outlook item, so an error occurs when calling any property other than Class or MessageClass for the Outlook item returned in Item. Similarly, an error occurs if you attempt to call any method from the Outlook item, or if you call the GetObjectReference method of the Application object on the Outlook item returned in Item.

The aim behind my AddIn is, to display a DropDownBox in the Ribbon Bar where the displayed items depend on the value of the subject (and some other properties) of the appointment. So is there a way to access the properties of the appointment during the eventhandler? Or is there any ohter eventhandler where I can change the DropDownBox while the Appointment gets loadad?

Thank you & regards Andi

1
just a wild guess: Try hooking the AppointmentItem.ReadComplete Event msdn.microsoft.com/en-us/library/office/jj229473.aspx and the properties should be theretobsen
I tried, your idea, but how do i get current Appointment? The statement this.Application.ActiveInspector().CurrentItem as Outlook.AppointmentItem; doesn't work.Andi K
Doesn't it work if you changed your example and regsitered the ReadComplete event for your appointmentItem = Item as Outlook.AppointmentItem;tobsen

1 Answers

0
votes

Having a similar issue, I found that properties were still inaccessible when registering the AppointmentItem.ReadComplete handler.

I did however have some success with the AppointmentItem.Read handler. Inside the method of the handler I was able to access the properties.

My code looks as follows:

private Outlook.AppointmentItem _item;

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
   this.Application.ItemLoad += 
      new Outlook.ApplicationEvents_11_ItemLoadEventHandler(Application_ItemLoad);
}

private void Application_ItemLoad(object item)
{
   if (item is Outlook.AppointmentItem)
   {
      this._item = item as Outlook.AppointmentItem;
      this._item.Read += _item_Read;
    }
}

private void _item_read()
{
   // Example access of Recipients property
   var recipients = this._item.Recipients;
}