kairen
kairen

Reputation: 245

Addins can't capture calendar event on Outlook 2010 32bit

As guidance on internet, I wrote an example addin to capture calendar(appointment) add/remove/change event, this is my code:

    private Outlook.Folder mOutlookFolder = null;
    private Outlook.Items mItems = null;

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        mOutlookFolder = (Outlook.Folder)Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);

        mItems = mOutlookFolder.Items;
        mItems.ItemChange += new Outlook.ItemsEvents_ItemChangeEventHandler(CalendarItems_ItemChange);
        mItems.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(CalendarItems_ItemAdd);
        mItems.ItemRemove += new Outlook.ItemsEvents_ItemRemoveEventHandler(CalendarItems_ItemRemove);
    }

    private void CalendarItems_ItemChange(object Item)
    {
        MessageBox.Show("########## CHANGE");
    }
    private void CalendarItems_ItemAdd(object Item)
    {
        MessageBox.Show("########## ADD");
    }
    private void CalendarItems_ItemRemove()
    {
        MessageBox.Show("########## REMOVE");
    }

It works fine on Outlook 2013 64bit but when I try with outlook 2010 32bit, the events aren't fired. So what's going on here ?

Upvotes: 1

Views: 337

Answers (2)

Insane
Insane

Reputation: 664

I faced the same issue with Calendar items. Declaring the items 'static' solved it for me.

private static Outlook.Folder mOutlookFolder = null;
private static Outlook.Items mItems = null;

Upvotes: 1

Eugene Astafiev
Eugene Astafiev

Reputation: 49405

The code should work in Outlook 2010 x86 or x64 as well. See Running Solutions in Different Versions of Microsoft Office for more information.

Most probably the add-in was disabled by Outlook. Check out the LoadBehavior windows registry key or the COM add-ins dialog in Outlook.

Microsoft Office applications can disable add-ins that behave unexpectedly. If an application does not load your add-in, the application might have hard disabled or soft disabled your add-in.

Hard disabling can occur when an add-in causes the application to close unexpectedly. It might also occur on your development computer if you stop the debugger while the Startup event handler in your add-in is executing.

Soft disabling can occur when an add-in produces an error that does not cause the application to unexpectedly close. For example, an application might soft disable an add-in if it throws an unhandled exception while the Startup event handler is executing.

When you re-enable a soft-disabled add-in, the application immediately attempts to load the add-in. If the problem that initially caused the application to soft disable the add-in has not been fixed, the application will soft disable the add-in again.

See How to: Re-enable an Add-in That Has Been Disabled for more information.

Upvotes: 3

Related Questions