Monitoring Appointments for Changes

Add-in Express™ Support Service
That's what is more important than anything else

Monitoring Appointments for Changes
 
Darrin Edwards


Guest


Hi guys,

Using Outlook Regions - have a VSTO which lists appointments. All works fine. What I would like to do if have the VSTO refresh when a user adds an appointment, so I need to set up a listener - can you provide a small example of how you would do that please ?

MTIA

DWE
Posted 03 Sep, 2019 23:17:25 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Darrin,

We do not provide VSTO examples. What you need to do is this:

- Get the Outlook.MAPIFolder (or Outlook.Folder; it derives from Outlook.MAPIFolder) object representing the folder that you need to monitor.
- Get MAPIFolder.Items; this returns the Outlook.Items object representing a collection of items in that folder.
- Connect to the Items.AddItem event of the Outlook.Items object. Optionally, you can also connect to the ItemChange and ItemRemove event; the latter doesn't let you know what exactly item has been removed.


Andrei Smolin
Add-in Express Team Leader
Posted 04 Sep, 2019 03:55:57 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
I'm pretty sure you can find such examples in the Outlook for Developers forum at https://social.msdn.microsoft.com/Forums/en-US/home?forum=outlookdev.


Andrei Smolin
Add-in Express Team Leader
Posted 04 Sep, 2019 03:59:50 Top
Darrin Edwards


Guest


Hi guys

for anyone else looking at a similar issue, there are a few classes written by http://adriandev.blogspot.com/2008/01/listening-to-calendar-events-with.html which assisted me in resolving my issue.

Regards

Darrin
Posted 04 Sep, 2019 15:55:09 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Darrin,

Thank you for pointing to that page.

On the technical side of that example, you should modify it to handle several Explorer objects and several stores: each may have a separate Calendar and Deleted Items folders. Also, IsUsersCalendar is seemingly incorrect: it is my understanding that every folder has the Store property non-empty.

I urge you to be very careful with COM objects created and left unreleased by that or any other code: you should release all of them. Ideally, you should release a COM object as soon as possible; right after you've used it is the best moment. In case of Office, any call to a property or method returning a complex type (not string, number, Boolean or enum) is a COM object.

In that example I see that all objects from the Outlook object model hold on the class level of the Monitor class are never released:
- _explorer;
- all Outlook.MAPIFolder objects stored in _calendarFolders;
- all Outlook.Items objects stored in _calendarItems;
- _deletedItemsFolder; note that this one is only used to provide the folder's EntryId when required; this suggests that you need to store the EntryId, not the folder.

In CalendarItems_ItemAdd, the event handler receives the item added, cast it to Outlook.AppointmentItem, handles it, and release it. That's okay. But, if you add any other item type to the calendar folder, that code will leave that item unreleased since it only releases AppointmentItem objects.


Andrei Smolin
Add-in Express Team Leader
Posted 05 Sep, 2019 02:55:40 Top