Outlook Item Types

Hello,

I have a PST with many folders and items that I am looking at with Aspose. I would like to cast each item to the appropriate Mapi type in Aspose such as MapiMessage, MapiJournal, MapiCalendar, MapiContact and so on. What is the recommended way to do this?

For example I found this snippet of code in the documentation relating to Calendar items, but what if I did not know that the current item was going to be a Calendar item or any other type in particular?

From Working with Calendar Items in PST File|Documentation

FolderInfo folderInfo = pst.RootFolder.GetSubFolder(“Calendar”);
MessageInfoCollection messageInfoCollection = folderInfo.GetContents();
foreach (MessageInfo messageInfo in messageInfoCollection)
{
MapiCalendar calendar = (MapiCalendar)pst.ExtractMessage(messageInfo).ToMapiMessageItem();
}

Thank you for any help

I found an answer..

The ToMapiMessageItem() function returns an IMapiMessageItem result, but you can check the type from there like this:

private void ProcessMAPIMsg(MapiMessage msg)
{
IMapiMessageItem message = msg.ToMapiMessageItem();

if (message is Aspose.Email.Outlook.MapiJournal)
{
//cast and do journal-specific code
}
}

Hi Duncan,


We are glad to know that you found the appropriate solution to your problem and shared your findings with us.

Please feel free to write us if you have any further queries