0

I am trying to find a way do undelete one/single Outlook AppointmentItem recurrence exception without impacting other recurrence exceptions. Here is snippet:

Outlook.AppointmentItem oa = OutlookNameSpace.GetItemFromID(oid);
var rp = oa.GetRecurrencePattern();
var exceptions = rp.Exceptions;

//there are 5 recurrence exceptions
Assert.AreEqual(5, exceptions.Count);

var e = exceptions[1];

//first exception is deleted           
Assert.IsTrue(e.Deleted);

//how to undelete the first exception?

I know the "brute force" solution posted here Remove Exceptions from a Series but I would like to avoid changes to other exceptions...

PPA
  • 25
  • 6

2 Answers2

1

The Exception.AppointmentItem object is not available for deleted items. You need to set up a new appointment using the Exception.OriginalDate property.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • OK. I can do that, but how to make this new appointment part of recurrence? So exception.Count is decreased – PPA May 10 '20 at 04:15
  • Thanks. The same action is required in case I have exception on one instance due to other change (for example one recurrence has changed hour) ? In such case I have AppointmentItem in exception, but how to repair master appointment to decrease number of exceptions ? – PPA May 10 '20 at 11:57
0

The reference found by Eugene is not strictly wrong, but I suspect it is misleading.

An AppointmentItem can have four values for property RecurrenceState:

Constant            Value   Significance
olApptNotRecurring  0       The appointment is not a recurring appointment.
olApptMaster        1       The appointment is a master appointment.
olApptOccurrence    2       The appointment is an occurrence of a recurring
                            appointment defined by a master appointment.
olApptException     3       The appointment is an exception to a recurrence
                            pattern defined by a master appointment.

From my own experimentation, you will only find the first two values if you search a Calendar folder. I believe olApptOccurrence can only be found in the return from a call of the RecurrencePattern.GetOccurrence method. I believe olApptException can only be found within an AppointmentItem with a RecurrenceState of olApptMaster. Of this, more later.

The AppointmentItem object contains all the properties for a non-recurring appointment. You use the AppointmentItem.GetRecurrencePattern method to get the additional properties for a recurring property.

AppointmentItem.GetRecurrencePattern returns a RecurrencePattern. A recurring appointment can occur one a year, once a month, once a week, once every Tuesday and Thursday and many other recurrences. All the details of the chosen recurrence are detailed in the RecurrencePattern.

One of the properties of an RecurrencePattern is the Exceptions collection. This collection contains one Exception object per exception. For your weekly project meeting you may be away one week or one week it might clash with a departmental meeting and its date, time and location changed. Each of these exceptions is detailed in an Exception object.

Two of the properties of an Exception object, are Deleted and AppointmentItem. For the project meeting you missing, Deleted will be True and there will be no AppointmentItem property for the Exception. For the project meeting that had to be moved, Deleted will be False and there will be a AppointmentItem property with a RecurrenceState of olApptExceptionfor the Exception describing the exceptional date, time, location, duration and so on.

The information I have found indicates you cannot change an Exception but you can “erase” one using techniques that depend on the language being used.

From https://learn.microsoft.com/en-us/office/vba/api/Outlook.Exception:

When you work with recurring appointment items, you should release any prior references, obtain new references to the recurring appointment item before you access or modify the item, and release these references as soon as you are finished and have saved the changes. This practice applies to the recurring AppointmentItem object, and any Exception or RecurrencePattern object. To release a reference in Visual Basic for Applications (VBA) or Visual Basic, set that existing object to Nothing. In C#, explicitly release the memory for that object. For a code example, see the topic for the AppointmentItem object.

The promised code is VB and may be found in https://learn.microsoft.com/en-us/office/vba/api/outlook.appointmentitem.

I do not have the time at present to experiment with deleting a deletion exception. I will add it to be to-do for later. You may wish to experiment now. I would be interested in the result of your experiment.

Tony Dallimore
  • 12,335
  • 7
  • 32
  • 61
  • Eugene gave good answer, in fact I am not looking for snippets from Microsoft documentation - I know all of this. I am looking for practical knowledge. Your answer is completely misleading (especially last part). This part in Microsoft documents is about releasing COM object via ReleaseComObject. And I was asking if there is some way to undelete recurrence Exception, so it disappers from Exceptions collection. It is not straight forward as Exceptions are read only. – PPA May 10 '20 at 15:40
  • @PPA Everything in my answer except the last paragraph is the result of extensive research into how Outlook `AppointmentItem`s actually work rather than how the documentation says they work. I read you question as implying you do not know where Outlook stores the exceptions. I did not find this surprising. I find the documentation on calendars poor. Once you know the facts, you can look at a page and see what the author was trying to say but many are impenetrable. My answer was an attempt to explain how to work down the hierarchy to find any exceptions. – Tony Dallimore May 11 '20 at 11:19
  • While checking I had every reference correct, I discovered a page which claimed to show the code to delete exceptions in such a way that the exception count was reduced which is what I thought you wanted. When I next have some time to spend on calendars, I will certainly try to get that code working. It is your choice if you do not want to try it. – Tony Dallimore May 11 '20 at 11:19
  • @TonyDallimore I am very interested in finding any code that manages to update an recurring.exception in any way. I actually like to changes it category. – Oliver Meyer Feb 26 '21 at 14:29