PST (Personal Storage Table) is a storage file format that is used by different Microsoft programs such as MS Outlook, Exchange, and Windows Messaging. PST files are capable of storing messages, contacts, calendars, events, etc. In certain cases, you may need to parse a PST file and extract data from it programmatically. To achieve that, this article shows how to read MS Outlook PST files using C# .NET. Particularly, you will learn how to extract folders’ information, read emails and fetch contacts from a PST file.
- .NET API to Read Outlook PST Files
- Read a PST File in C#
- Read Emails from a PST File
- Extract Contacts from a PST File
.NET API to Read Outlook PST Files
Aspose.Email for .NET is a powerful email processing API that lets you create and send emails from within .NET applications. In addition, it supports working with popular email and storage file formats. We will use this API to read folders’ information, messages, and contacts from PST files. You can either download the API or install it via NuGet.
PM> Install-Package Aspose.Email -Version 22.3.0
Read an Outlook PST File in C# .NET
The following are the steps to read a PST file and extract its information in C#.
- Load the PST file using PersonalStorage.FromFile() method.
- Get the folders collection in PST using PersonalStorage.RootFolder.GetSubFolders() method.
- Retrieve the information of the folders such as name, number of items, etc.
The following code sample shows how to parse a PST file and fetch folders’ information.
Read Emails from a PST File in C#
Emails are the major entities that are stored in PST files by MS Outlook. So let’s see how to read email messages from a PST file in C#.
- Load the PST file using PersonalStorage.FromFile() method.
- Access the root folder using PersonalStorage.RootFolder property.
- Get message collection using FolderInfo.GetContents() method.
- Loop through the messages in the collection and read each message’s fields.
The following code sample shows how to extract messages from a PST file in C# .NET.
Extract Contacts from a PST File in C#
In certain cases, you may need to extract the contacts’ information stored in a PST file. The following steps demonstrate how to access the contacts in a PST file in C#.
- Load the PST file using PersonalStorage.FromFile() method.
- Get reference of the contacts folder using PersonalStorage.RootFolder.GetSubFolder(“Contacts”) method.
- Get collection of contacts using FolderInfo.GetContents() method.
- Loop through the contacts collection and read each contact or save it.
The following code sample shows how to extract contacts from a PST file in C#.
Get a Free API License
You can try Aspose.Email for .NET for free by getting a temporary license.
Conclusion
In this article, you have learned how to read PST files programmatically in C# .NET. Furthermore, you have seen how to read folder information, fetch emails, and extract contacts from a PST file in C#. Besides, you can explore more about Aspose.Email for .NET using documentation. Also, you can share your questions or queries on our forum.