We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

[.Net] Exporting items out of a PST - Performance

Hello,
I just started using the Aspose .Net Email API and wanted your opinion on a piece of code. I have the code snippet below that opens a PST and goes through all folders and exports all items it finds to the files system as MSG files. Is this the fastest way to do this or is there another way that would perform better ? Right now I have just a few folders in my PST and maybe around 30 emails in there. It takes around 2-3 seconds. Any suggestions for optimization to make it faster would be greatly appreciated.

  internal static void Export(string pstFile)
    {
        using (PersonalStorage personalStorage = PersonalStorage.FromFile(pstFile))
        {
            ProcessFolder(personalStorage.RootFolder, personalStorage);
        }
    }

    static void ProcessFolder(FolderInfo folder, PersonalStorage pst)
    {
        string fullpath = folder.RetrieveFullPath();
        Directory.CreateDirectory("D:\\Temp\\Aspose\\" + fullpath);

        foreach (var message in folder.EnumerateMessages())
        {

            using (FileStream fs = new FileStream("D:\\Temp\\Aspose\\" + fullpath + "\\" + GetFileName(message.Subject + message.EntryIdString) + ".msg", FileMode.Create))
                pst.SaveMessageToStream(message.EntryIdString, fs);
        }

        if (folder.HasSubFolders)
        {
            foreach(var subFolder in folder.GetSubFolders())
            {
                ProcessFolder(subFolder, pst);
            }
        }
    }

@azsand,

This is the right way to enumerate messages inside PST. Please visit this documentation section for your kind reference as well.