[C#/Office PIA]Outlook throws "Unknown error" when I insert calendarappointments

  • Thread starter Chris van Kordenoordt
  • Start date
C

Chris van Kordenoordt

I have created an application in C# with VS2005 that is supposed to get
appointments from a central database and insert them into the users
Outlook calendar. I use the Office 2003 PIA to accomplish this.

When I insert appointments in my testing environment everything works
just peachy. In the production environment however, which is quite a bit
slower, Outlook gives out after about 20-30 appointments with the error:
"Unknown error" and after that: "Can't open the item". This happens when
I try to delete some of the items in Outlook that are an exception to a
recurring appointment.

I suspect there is something that needs to be flushed or cleared after
inserting an appointment, but I can't seem to find a suitable solution.
The code I use(simplified -- only the outlook parts are shown) is shown
below. Appointment is a custom object that contains the properties of my
appointments.

My question: Is this a good way to remove the exceptions from a
recurring appointment in Outlook or is there a better way to do this? Am
I using the PIA the right way?

If there is any additional information needed that I haven't yet
provided, please ask.

Thanks in advance, this has been bugging me for days.

Chris

-------
private void RemoveExceptions(Appointment appointment)
{
//Set Outlook API parameters
Outlook._Application outlookApp = (Outlook._Application)new
Outlook.Application();
Outlook.NameSpace mapiNamespace;
Outlook.MAPIFolder olCalendar;
mapiNamespace = outlookApp.GetNamespace("MAPI");
olCalendar =
mapiNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);

//Get the appointment I want to edit from Outlook
Outlook._AppointmentItem olAppointment =
(Outlook._AppointmentItem)mapiNamespace.GetItemFromID(appointment.OutlookId,
olCalendar.StoreID);

mapiNamespace.Logon(null, null, null, null);


for (//do some loop)
{
//Get the item that is an exception and delete it
try
{
Outlook._AppointmentItem item =
olAppointment.GetRecurrencePattern().GetOccurrence(//somedate);
if (item != null)
item.Delete();
}
catch (Exception){}
}
}
//Save and close the appointment
olAppointment.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olSave);
mapiNamespace.Logoff();
}
 
B

Brian Tillman

Chris van Kordenoordt said:
I have created an application in C# with VS2005 that is supposed to
get appointments from a central database and insert them into the
users Outlook calendar. I use the Office 2003 PIA to accomplish this.

You may get better advice in the programming groups:
microsoft.public.outlook.program_addins
microsoft.public.outlook.program_vba
 

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