This project has moved and is read-only. For the latest updates, please go here.

watching folder for changes

Jun 24, 2016 at 7:23 PM

I wanted to ask how to register for a change of items in a folder. It seems like I can't get access to the event.

In VSTO I would write for example:
var folder = this.Application.Session.GetDefaultFolder(OlDefaultFolders.olFolderToDo);
((ItemsEvents_Event)folder.Items).ItemAdd += item => { ... }
It looks like ItemsEvents_Event does not exist in Netoffice?

Jun 25, 2016 at 12:04 AM
Of course NetOffice want support ItemsEvents_Event.
Any event name in NetOffice comes with "Event" as postfix.
So "ItemAdd" is now "ItemAddEvent" in NetOffice.

The reason is because a lot of events in office classes use events/properties/methods with the same name.
For example Excel.Range has an "Activate();" method and an "event Activate;" event. (Moreover Excel.Range has a method called Range but the name of the class in .Net is preserved for the .ctor) This is allowed in COM (which Office comes from) but not suitable in .Net Languages.

In order to prevent this downcast(you do here) NetOffice do this one breaking syntax change for events.
(Other COM/.Net issues with Properties/methods with same name was resolved by an intermediate base the base class can have the same property name like the top class methods...only visual face some problems here...)

let me know this helps
Jun 26, 2016 at 9:04 PM
Hi Sebastian,

thanks for yor reply. As a result I have finally been able to find the reason for my problem:
I need to cast the Items collection to Outlook.Items.

I wanted to suggest to add this use-case to the tutorials or examples.

For me the following code works now:
        var todoFolder = session.GetDefaultFolder(OlDefaultFolders.olFolderToDo);
        var todoFolderItems = (Outlook.Items)todoFolder.Items;
        todoFolderItems.ItemAddEvent += Items_ItemAddEvent;
        todoFolderItems.ItemRemoveEvent += Items_ItemRemoveEvent;
        todoFolderItems.ItemChangeEvent += Items_ItemChangeEvent;
thanks for your help,