Exception while loading Appointment in MapiMessage

Hi,

Trying to execute code :
Appointment app = Appointment.load(new ByteArrayInputStream(buffer));
MailMessage msg = new MailMessage();
msg.addAlternateView(app.requestApointment());
MapiMessage mapi = MapiMessage.fromMailMessage(msg);
restoreFolder.addMapiMessageItem(mapi);

Where restore folder is container class - IPF.Appointment
And getting next exception :
java.lang.ClassCastException: com.aspose.email.MapiMessage cannot be cast to com.aspose.email.MapiCalendar
at com.aspose.email.FolderInfo.addMapiMessageItem(Unknown Source)

Please advise.

Hi Slava,

Thank you for writing to Aspose support.

I have analyzed your code sample and have found that you are not casting the MapiMessage to MapiCalendar that raises this exception. Please have a look at the following code sample that successfully adds the Appointment to the PST and let us know your feedback.

Sample Code:

Appointment app = Appointment.load("App.ics");
PersonalStorage pst = PersonalStorage.create("testPst.pst", FileFormatVersion.Unicode);
FolderInfo restoreFolder = pst.createPredefinedFolder("Calendar", StandardIpmFolder.Appointments);
System.out.println(restoreFolder.getContainerClass());
MailMessage msg = new MailMessage();
msg.addAlternateView(app.requestApointment());
MapiMessage mapi = MapiMessage.fromMailMessage(msg);
MapiCalendar cal = (MapiCalendar)mapi.toMapiMessageItem();
restoreFolder.addMapiMessageItem(cal);
pst.dispose();