How to update recurrece exceptions?

H

huangbo888

I am writting an Outlook Add-In and allowed user to perfrom calendar
sync with outlook. I have trouble in creatting and updating recurrence
exception appointment
in outlook, and I am using C# and Outlook Object Model.

I do some testing by the fllowing steps:

1. Manually create a recurrence appointment in outook and the
recurrence type is daily.

2. Manually create a recurrence exception appointment by changing an
occurence appointment subject.

3. Update recurrence exception appointment start time and date time
by Outlook object model and C#, sample code shows below:

AppointmentItem aptItem;

//Get the recurrence appointment item from Calendar folder
AppointmentItem aptItem = GetAnRecurrenceAppointmentItem();

RecurrencePattern pattern = aptItem.GetRecurrencePattern();
Microsoft.Office.Interop.Outlook.Exceptions exceptions =
pattern.Exceptions;

IEnumerator en = exceptions.GetEnumerator();
while (en.MoveNext())
{
Microsoft.Office.Interop.Outlook.Exception ex = en.Current
as Microsoft.Office.Interop.Outlook.Exception;

// Get recurrence appointment Item
AppointmentItem item = ex.AppointmentItem;

//Update start and end datetime by adding one day.
item.Start = new DateTime(item.Start.Year,
item.Start.Month, item.Start.Day + 1, 18, 0, 0);
item.End= new DateTime(item.End.Year, item.End.Month,
item.End.Day + 1, 19, 0, 0);

// it throws COM Exceptions when saving
item.Save();

break;
}

The above code throws COM exception says that the item can not be
saved.

Is there a approach to update an existing recurrence exception?

Thanks
Bo
 
K

Ken Slovak - [MVP - Outlook]

That exception usually occurs because you are holding a different reference
to that object somewhere and haven't released it. That then causes the
exception. You should review all of your code to make sure that any
references to the objects are released correctly and that only the object
reference you are using Save() on is valid at that time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top