PersonalStorage

PersonalStorage class

Provides functionality to access and manipulate the PST (Personal Storage Table) files used by Microsoft Outlook.

The PersonalStorage class encapsulates methods for creating, opening, and working with the contents of PST files including emails, appointments, contacts, tasks, and other personal information.

This code serves as a way to browse and extract messages from a PST file, printing metadata about each folder and message, extract and saving the actual messages as .msg files.

// Open the PST file by creating an instance of PersonalStorage
using (var pst = PersonalStorage.FromFile("storage.pst"))
{
 // Retrieve the total number of items in the PST file
    var totalItemsCount = pst.Store.GetTotalItemsCount();
 
 // Write the total items count to the console
    Console.WriteLine($"Total items count: {totalItemsCount}");
 
 // Iterate through each subfolder within the root folder of the PST
 foreach (var folderInfo in pst.RootFolder.GetSubFolders())
    {
 // Write the display name of the folder to the console
        Console.WriteLine($"Folder: {folderInfo.DisplayName}");
 // Write the total number of items in the folder to the console
        Console.WriteLine($"Total items: {folderInfo.ContentCount}");
 // Write the count of unread items in the folder to the console
        Console.WriteLine($"Total unread items: {folderInfo.ContentUnreadCount}");
 
 // Enumerate through each message in the current folder
 foreach (var messageInfo in folderInfo.EnumerateMessages())
        {
 // Write the subject of the message to the console
            Console.WriteLine($"Subject: {messageInfo.Subject}");
 
 // Extract the full message object from the messageInfo
            var msg = pst.ExtractMessage(messageInfo);
 
 // Save the message as a .msg file, using its subject as the filename
            msg.Save($"{msg.Subject}.msg");
        }
    }
}
' Open the PST file by creating an instance of PersonalStorage
Using pst As PersonalStorage = PersonalStorage.FromFile("storage.pst")
    ' Retrieve the total number of items in the PST file
    Dim totalItemsCount As Integer = pst.Store.GetTotalItemsCount()
 
 ' Write the total items count to the console
    Console.WriteLine($"Total items count: {totalItemsCount}")
 
    ' Iterate through each subfolder within the root folder of the PST
    For Each folderInfo In pst.RootFolder.GetSubFolders()
 ' Write the display name of the folder to the console
        Console.WriteLine($"Folder: {folderInfo.DisplayName}")
        ' Write the total number of items in the folder to the console
        Console.WriteLine($"Total items: {folderInfo.ContentCount}")
 ' Write the count of unread items in the folder to the console
        Console.WriteLine($"Total unread items: {folderInfo.ContentUnreadCount}")
 
        ' Enumerate through each message in the current folder
        For Each messageInfo In folderInfo.EnumerateMessages()
 ' Write the subject of the message to the console
            Console.WriteLine($"Subject: {messageInfo.Subject}")
 
            ' Extract the full message object from the messageInfo
            Dim msg As MailItem = pst.ExtractMessage(messageInfo)
 
 ' Save the message as a .msg file, using its subject as the filename
            msg.Save($"{msg.Subject}.msg")
        Next
    Next
End Using

Constructors

NameDescription
PersonalStorageInitializes a new instance of the PersonalStorage class. Allows setting a callback method for handling exceptions that occur during PST traversal.

Methods

NameDescription
AddAttachmentToMessage (4 overloads)Adds an attachment to the specified message using the file located at the provided path.
CancelThis method used to interrupt a split operation.
ChangeMessageChanges the message properties.
CloneFolderStructureClones the folder structure.
ConvertToConverts the current object to the specified format.
Create (3 overloads)Creates the PST in a stream.
CreateFolderMappingClones the folder structure.
CreatePredefinedFolder (2 overloads)Creates the standard interpersonal message (IPM) folder.
DeleteItemDeletes the item (folder or message) by it’s entryId
Dispose (2 overloads)Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
EnumerateMessages (2 overloads)Exposes the enumerator, which supports an iteration of messages in folder.
ExtractAttachments (2 overloads)Extracts the attachments.
ExtractMessage (3 overloads)Get the message from PST.
ExtractPropertyGets the specified property of item, without extract the item fully.
ExtractRecipients (2 overloads)Extracts the recipients.
FindAndExtractSoftDeletedItemsFinds and extracts soft-deleted messages from the PST.
FindMessagesFinds the identifiers of messages for for the current folder. It might be useful in case of reading corrupted pst when the GetContents and EnumerateMessages methods could throw an exception.
FindSubfoldersFinds the identifiers of subfolders for for the current folder. It might be useful in case of reading corrupted pst when the GetSubfolders and EnumerateFolders methods could throw an exception.
FromFile (3 overloads)Load PST from file.
FromStream (3 overloads)Load PST from stream.
get_CanWriteGets a value indicating whether the current pst supports writing.
get_FormatGets the file format.
get_IsUnicodeGets a value indicating whether the PST file format is Unicode. There are two versions of the PST file format: Unicode and ANSI.
get_RootFolderGets the root folder of PST.
get_StoreGets the PST message store.
GetCategoriesRetrieves a list of PST item categories, each containing a name and associated color.
GetFolderById (2 overloads)Gets the personal folder from PST.
GetParentFolder (2 overloads)Gets the parent folder of message.
GetPredefinedFolderGets the standard interpersonal message (IPM) folder from PST. Outlook can create a number of default folders, such as Outbox, Deleted Items, Sent Items etc.
GetVentureLicenseState
Load (2 overloads)Load PST from stream. This method is used when a PersonalStorage object is created using the constructor.
MergeWith (2 overloads)Merges the pst storage with one or more other pst streams. Thus, the combined stream are sources.
MoveItem (2 overloads)Moves a specified folder to a new parent folder within the current pst.
OnStorageProcessedRaises the E:ChunkCreated event.
SaveAs (2 overloads)Saves the current object to a specified file format in a stream.
SaveMessageToStreamSaves the message, with specified entryID, to a stream.
SplitInto (4 overloads)Splits the pst storage into less sized parts.
TryToGetFolderByIdGets the folder associated with the specified entry ID.
TryToSaveMessageSaves the message, with specified entryID, to a stream.
ItemMovedOccurs when an item is moved to the another folder.
pstDoerThe pst reader.
StorageProcessedOccurs in splitting and merging operations when a new chunk of pst is created or the next file is processed and is to be merged.
StorageProcessingOccurs before the srorage is processed. The event is raised before processing the next storage in merging or splitting operations.