PSTFileFormat icon indicating copy to clipboard operation
PSTFileFormat copied to clipboard

Error while adding attachment to message

Open kartikeysemwal opened this issue 2 years ago • 0 comments

I am trying to add attachment to a message but getting error System.Exception: 'Cannot get subnode: missing data tree root. I tried to test with various combinations of SaveChanges() on various data items but nothing worked.

` using System.Net; using System.Text; using System.Xml; using System.Xml.Linq; using System.Text.RegularExpressions;

namespace PSTFileFormat { class Program { static void Main(string[] args) { PSTFile pstFile = new PSTFile(@"D:\ksemwal\Temp\PSTFiles\SimpleEmailPST2.pst");

        var topFolder = pstFile.TopOfPersonalFolders;

        pstFile.BeginSavingChanges();

        foreach (var folder in topFolder.GetChildFolders())
        {
            System.Console.WriteLine(folder.DisplayName);

            if(folder.MessageCount > 0)
            {
                MessageObject curMessage = folder.GetMessage(0);
                System.Console.WriteLine(curMessage.Subject);

                AttachmentObject attachmentObject = AttachmentObject.CreateNewExceptionAttachmentObject(pstFile, curMessage.SubnodeBTree);
                attachmentObject.SaveChanges();

                curMessage.AddAttachment(attachmentObject);
                curMessage.SaveChanges();
                folder.SaveChanges();
            }
        }

        topFolder.SaveChanges();
        pstFile.EndSavingChanges();
        pstFile.CommitChanges();
    }
}

} `

kartikeysemwal avatar Apr 14 '23 04:04 kartikeysemwal