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:
- Create a PST using the PersonalStorage.create() method.
- Add a sub-folder at the PST root by accessing the Root folder and calling the addSubFolder() method.
- Add a message to the newly created folder by calling addMessage and passing a MapiMessage as a parameter.
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.
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.
To add messages from another PST, use the FolderInfo.enumerateMapiMessages() method that returns IEnumerable<MapiMessage>: