Skip to content

Error while adding attachment to message #3

@kartikeysemwal

Description

@kartikeysemwal

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();
    }
}

}
`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions