0

I'm developing an Outlook AddIn using the NetOffice library, but I guess the problem is similar for VSTO.

I want to handle following events in Outlook regarding appointments:

  • The user drag'n'drops appointments to change the date of the appoinment
  • The user double clicks the appointment subject and edits it directly on the calendar
  • The user gets an ICS file by email which updates some data on the appointment

So that's pretty easy:

        var exp = App.Session.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
        (exp.Items as Items).ItemChangeEvent += Addin_ItemChangeEvent;

So now on each case I need, my event handler fires up. However the problem is, that I need to recognize, if the change on the appointment is because of user action on the calendar or an ICS file received.

I really stuck on that one, any tips?

alek kowalczyk
  • 4,896
  • 1
  • 26
  • 55

1 Answers1

1

You can use marks for that. I try to explain my solution. In each outlook item (it can be AppointmentItem and MailItem) you have a property UserProperties, you can create mark variable like a string public const string ICSMark = "ICSMark"and add new user property with this mark appointmentItem.UserProperties.Add(ICSMark, OlUserPropertyType.olText);. When you event is occurs you can check your item for this mark UserProperty mark = appointmentItem.UserProperties.Find(ICSMark);, if mark is not null, it was updated from ICS file.

Aliaksei Futryn
  • 461
  • 5
  • 8
  • I'm using `UserProperties` a lot, but when should I set this mark to know that the event comes from an ICS file and not from drag'n'drop? – alek kowalczyk Apr 21 '16 at 15:32
  • For instance you can set mark after dran'n'drop. When event occurs you can check this mark and if event doesn't contains this mark so event was moved by drag'n'drop. – Aliaksei Futryn Apr 22 '16 at 11:20
  • But which event occurs after drag'n'drop? Because the `ItemChangeEvent` gets fired not only after d'n'd but also when an ICS makes the change. So how can I set a mark? Are there another usable events? – alek kowalczyk Apr 22 '16 at 13:50
  • When you received event you can set start and end time into 'UserProperties'. After that when 'ItemChangeEvent' occurs you can obtain values from these marks and compare them with start and end time. If you have differences, so event was been dra'n'drop. – Aliaksei Futryn Apr 22 '16 at 14:10
  • But couldn't those differences be also due to the received ICS file? The ics file may update the appointment with new start/end dates, isn't it? – alek kowalczyk Apr 22 '16 at 14:15
  • Just noticed that the `ConversationIndex` property changes on ICS update, but doesn't change on drag'n'drop, so using that information I can differentiate between those events. But the subject editing directly on the calendar changed the property as well, so now I'm stuck how to now that the subject was changed directly on the calendar, and not through an ICS update. – alek kowalczyk Apr 22 '16 at 15:04