Reputation: 13
I have Outlook 2013 with 2 accounts registrered, so the problem is when I try to attach the ItemAdd and the ItemChange events to the calendar accounts, in the main account it works perfectly, but in the second account not handle the events, My code is this:
Outlook.MAPIFolder calendarFolder = null;
Outlook.Items calendarItems = null;
private void AddinModule_AddinInitialize(object sender, EventArgs e)
{
calendarFolder = this.OutlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
calendarItems = calendarFolder.Items;
calendarItems.ItemAdd += this.ItemAdd;
calendarItems.ItemChange += this.ItemChange;
}
I think the problem is that calendarItems not show the items of secundary account and for this reason not handle the events, but I need to handle the events for two or more calendar accounts.
Upvotes: 0
Views: 617
Reputation: 49455
I see the code for subscribing to the event of the default delivery store only:
calendarFolder = this.OutlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
calendarItems = calendarFolder.Items;
Instead, you need to iterate over all Stores in the profile (2 in your case) and get the calendar folder using the GetDefaultFolder method of the Store class which returns a Folder object that represents the default folder in the store and that is of the type specified by the FolderType argument. This method is similar to the GetDefaultFolder method of the NameSpace object. The difference is that this method gets the default folder on the delivery store that is associated with the account, whereas NameSpace.GetDefaultFolder returns the default folder on the default store for the current profile.
The Stores property of the Namespace class returns a Stores collection object that represents all the Store objects in the current profile.
P.S. I see that you use ADX. In that case you can use ADXOutlookItemsEvents for handling Items event easily. Take a look at the Getting started guide for developers for more information.
Upvotes: 0
Reputation: 66286
calendarItems variable must be declared on the global (class) level to prevent it from being destroyed by the garbage collector.
Upvotes: 0