public static void Run()
{
// ExStart:SaveMessagesDirectlyFromPSTToStream
// The path to the file directory.
string dataDir = RunExamples.GetDataDir_Outlook();
// Load the Outlook file
string path = dataDir + "PersonalStorage.pst";
// Save message to file
using ( PersonalStorage personalStorage = PersonalStorage.FromFile(path))
{
FolderInfo inbox = personalStorage.RootFolder.GetSubFolder("Inbox");
foreach (MessageInfo messageInfo in inbox.EnumerateMessages())
{
using (FileStream fs = File.OpenWrite(messageInfo.Subject + ".msg"))
{
personalStorage.SaveMessageToStream(messageInfo.EntryIdString, fs);
}
}
}
// ExEnd:SaveMessagesDirectlyFromPSTToStream
}
}