How to Create a PST File in C#

This step-by-step article guides how to create a PST file in C# by providing references for establishing the environment and then program flow to perform this task. A runnable sample code is also shared that can be used in any of the .NET supported environments without installing any other third-party tool or MS Outlook for creating the new PST file. Once you create PST in C# it can be saved on the disk or to a stream as per the application requirements.

Steps to Create a PST File in C#

  1. Setup development environment to add Aspose.Email for .NET from NuGet package manager
  2. Create an object of PersonalStorage by providing the new PST file name and file format version
  3. Create a predefined folder in the root folder of the PST
  4. Add some custom folders in the root folder
  5. Save the resultant PST file on disk

These steps describe the process to create a new PST in C# where first the classes are identified that can be used to create a PST file and then a few additional tasks are performed for better understanding. A PST file can be created by providing the PST file name and the file format version which can be either Unicode or ANSI. We can create a PST file without any folder however, we can add predefined or custom folders before saving the PST file.

Code to Create a New PST File in C#

This code demonstrates how to create Outlook PST file in C# by using one of the overloaded functions Create() that allows a variety of parameters. You can create predefined folders using the StandardIpmFolder enumerator that contains entries like Inbox, Outbox, SentItems, DeletedItems, Contacts, Tasks, etc. to name a few. You can also create custom folders that are not standard but required in your environment.

This article has taught us how to make a PST file in C#. If you want to learn the process to send an email in C#, refer to the article on How to send email in C#.

 English