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 MemoryStream
            using (PersonalStorage personalStorage = PersonalStorage.FromFile(path))
            {
                FolderInfo inbox = personalStorage.RootFolder.GetSubFolder("Inbox");
                foreach (MessageInfo messageInfo in inbox.EnumerateMessages())
                {
                    using (MemoryStream memeorystream = new MemoryStream())
                    {
                        personalStorage.SaveMessageToStream(messageInfo.EntryIdString, memeorystream);
                    }
                }
            }

            // Save message to file
            using (PersonalStorage pst = PersonalStorage.FromFile(path))
            {
                FolderInfo inbox = pst.RootFolder.GetSubFolder("Inbox");
                foreach (MessageInfo messageInfo in inbox.EnumerateMessages())
                {
                    using (FileStream fs = File.OpenWrite(messageInfo.Subject + ".msg"))
                    {
                        pst.SaveMessageToStream(messageInfo.EntryIdString, fs);
                    }
                }
            }

            using (PersonalStorage pst = PersonalStorage.FromFile(path))
            {
                FolderInfo inbox = pst.RootFolder.GetSubFolder("Inbox");

                // To enumerate entryId of messages you may use FolderInfo.EnumerateMessagesEntryId() method:
                foreach (string entryId in inbox.EnumerateMessagesEntryId())
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        pst.SaveMessageToStream(entryId, ms);
                    }
                }
            }
            // ExEnd:SaveMessagesDirectlyFromPSTToStream
        }
Exemplo n.º 2
0
        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
        }