PersonalStorage
Contents
[
Hide
]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
| Name | Description |
|---|---|
| PersonalStorage | Initializes a new instance of the PersonalStorage class. Allows setting a callback method for handling exceptions that occur during PST traversal. |
Methods
| Name | Description |
|---|---|
| AddAttachmentToMessage (4 overloads) | Adds an attachment to the specified message using the file located at the provided path. |
| Cancel | This method used to interrupt a split operation. |
| ChangeMessage | Changes the message properties. |
| CloneFolderStructure | Clones the folder structure. |
| ConvertTo | Converts the current object to the specified format. |
| Create (3 overloads) | Creates the PST in a stream. |
| CreateFolderMapping | Clones the folder structure. |
| CreatePredefinedFolder (2 overloads) | Creates the standard interpersonal message (IPM) folder. |
| DeleteItem | Deletes 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. |
| ExtractProperty | Gets the specified property of item, without extract the item fully. |
| ExtractRecipients (2 overloads) | Extracts the recipients. |
| FindAndExtractSoftDeletedItems | Finds and extracts soft-deleted messages from the PST. |
| FindMessages | Finds 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. |
| FindSubfolders | Finds 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_CanWrite | Gets a value indicating whether the current pst supports writing. |
| get_Format | Gets the file format. |
| get_IsUnicode | Gets a value indicating whether the PST file format is Unicode. There are two versions of the PST file format: Unicode and ANSI. |
| get_RootFolder | Gets the root folder of PST. |
| get_Store | Gets the PST message store. |
| GetCategories | Retrieves 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. |
| GetPredefinedFolder | Gets 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. |
| OnStorageProcessed | Raises the E:ChunkCreated event. |
| SaveAs (2 overloads) | Saves the current object to a specified file format in a stream. |
| SaveMessageToStream | Saves the message, with specified entryID, to a stream. |
| SplitInto (4 overloads) | Splits the pst storage into less sized parts. |
| TryToGetFolderById | Gets the folder associated with the specified entry ID. |
| TryToSaveMessage | Saves the message, with specified entryID, to a stream. |
| ItemMoved | Occurs when an item is moved to the another folder. |
| pstDoer | The pst reader. |
| StorageProcessed | Occurs in splitting and merging operations when a new chunk of pst is created or the next file is processed and is to be merged. |
| StorageProcessing | Occurs before the srorage is processed. The event is raised before processing the next storage in merging or splitting operations. |