public static void Run()
{
// The path to the File directory.
// ExStart:ExtractAttachmentsFromPSTMessages
string dataDir = RunExamples.GetDataDir_Outlook();
using (PersonalStorage personalstorage = PersonalStorage.FromFile(dataDir + "Outlook.pst"))
{
FolderInfo folder = personalstorage.RootFolder.GetSubFolder("Inbox");
foreach (var messageInfo in folder.EnumerateMessagesEntryId())
{
MapiAttachmentCollection attachments = personalstorage.ExtractAttachments(messageInfo);
if (attachments.Count != 0)
{
foreach (var attachment in attachments)
{
if (!string.IsNullOrEmpty(attachment.LongFileName))
{
if (attachment.LongFileName.Contains(".msg"))
{
continue;
}
else
{
attachment.Save(dataDir + @"\Attachments\" + attachment.LongFileName);
}
}
}
}
}
}
// ExEnd:ExtractAttachmentsFromPSTMessages
}
}