0
votes

I'm trying to copy appointment items from a pst file to a subfolder of type calender in the users mailbox(as an archive). I'm also copying mail items and contacts and that works perfectly. What I'm doing is make a copy of each item and moves it to the new location. The destination MAPIFolder is a subfolder of the user mailbox with subfolders of type(s) olFolderInbox, olFolderCalendar and olFolderContacts

 Microsoft.Office.Interop.Outlook.AppointmentItem clone = app.CreateItem((OlItemType.olAppointmentItem));
                    AppointmentItem source = item as  AppointmentItem;
                    clone = source.Copy();
                    clone.Move(destination);

Some items are getting copied (eg. an recurring all day event) But most is not. Instead the code is creating multiple copies in the source calendar of the pst file!

The exception is thrown when calling source.Copy() The exception I get:

System.ArgumentException was caught _HResult=-2147024809
_message=Could not complete the operation. One or more parameter values are not valid.
HResult=-2147024809 IsTransient=false  Message=Could not complete the operation.
One or more parameter values are not valid. Source=Microsoft Outlook StackTrace: at Microsoft.Office.Interop.Outlook._AppointmentItem.Copy()
   at Program.cs:line 679  InnerException:

As mentioned the same code runs fine on mail and contact items and on some calendar items.

Driving me crazy!! Please help.

Thanks

1

1 Answers

0
votes

Outlook tries to run its business logic when it decides whether a particular item can be copied or moved, and that invokes processing update/delete notifications, maybe even running form script (if a custom form is used). If using Redemption is an option, try something like the following - Redemption does not try to be fancy.

  RDOSession Session = new RDOSession();
  Session.MAPIOBJECT = Application.Session.MAPIOBJECT;
  RDOMail rItem = (RDOMail)Session.GetRDOObjectFromOutlookObject(item);
  RDOFolder rDestination = (RDOFolder)Session.GetRDOObjectFromOutlookObject(destination);
  rItem.CopyTo(rDestination);