Create New PST, Add Sub-folders and Messages

Skip to end of metadata
Go to start of metadata
Contents Summary

Apart from parsing an existing PST, Aspose.Email also provides the means to create a PST file from scratch. This article shows how to create a Microsoft Outlook PST file and add a sub-folder to it. It uses the PersonalStorage class to create the PST on disk.

Below are the steps to create PST from scratch:

  1. Create a PST using the PersonalStorage.create() method.
  2. Add a sub-folder at the PST root by accessing the Root folder and calling the addSubFolder() method.
  3. Add a message to the newly created folder by calling addMessage and passing a MapiMessage as a parameter.

Change a Folder's Container Class

Sometimes it is necessary to change a folder's container class. A common example is where messages of different types (appointments, messages, for example) are added to the same folder. In such cases, the folder class needs to be changed for all elements in the folder to display properly. The following code sample shows how to change the container class of a folder in PST for this purpose.

Add Bulk Messages with Improved Performance

Adding individual messages to a PST implies more I/O operations to disc and may slow down the performance. For improved performance, messages can be added to the PST in bulk mode to minimize I/O operations. The addMessages(IEnumerable<MapiMessage> messages) method allows you to add messages in bulk and can be used as in the following scenarios. In addition, the MessageAdded event occurs when a message is added to the folder.

Add Messages from Another PST

To add messages from another PST, use the FolderInfo.enumerateMapiMessages() method that returns IEnumerable<MapiMessage>:

Adding Bulk Messages from Disc

Example Code for IEnumerable Implementation for Adding Messages from Files in a Directory

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.