Aspose.Email.Examples.CSharp.Email.Outlook.ExtractMessagesFromPSTFile.ExtractMsgFiles C# (CSharp) Method

ExtractMsgFiles() private static method

This is a recursive method to display contents of a folder
private static ExtractMsgFiles ( FolderInfo folderInfo, PersonalStorage pst ) : void
folderInfo FolderInfo
pst PersonalStorage
return void
        private static void ExtractMsgFiles(FolderInfo folderInfo, PersonalStorage pst)
        {
            // ExStart:ExtractMessagesFromPSTFileExtractMsgFiles
            // display the folder name
            Console.WriteLine("Folder: " + folderInfo.DisplayName);
            Console.WriteLine("==================================");
            // loop through all the messages in this folder
            MessageInfoCollection messageInfoCollection = folderInfo.GetContents();
            foreach (MessageInfo messageInfo in messageInfoCollection)
            {
                Console.WriteLine("Saving message {0} ....", messageInfo.Subject);
                // get the message in MapiMessage instance
                MapiMessage message = pst.ExtractMessage(messageInfo);
                // save this message to disk in msg format
                message.Save(message.Subject.Replace(":", " ") + ".msg");
                // save this message to stream in msg format
                MemoryStream messageStream = new MemoryStream();
                message.Save(messageStream);
            }

            // Call this method recursively for each subfolder
            if (folderInfo.HasSubFolders == true)
            {
                foreach (FolderInfo subfolderInfo in folderInfo.GetSubFolders())
                {
                    ExtractMsgFiles(subfolderInfo, pst);
                }
            }
            // ExEnd:ExtractMessagesFromPSTFileExtractMsgFiles
        }
    }
ExtractMessagesFromPSTFile