Bookmark text in the document cannot be updated. Exception is thrown

Hi,

I am trying to update bookmark text in the document and i am getting the following exception: Parent cannot be null.

Document mDocument = new Aspose.Words.Document(DocFileName);
Bookmark AddendumBookmark = mDocument.Range.Bookmarks["START36634100479726875000F"];
AddendumBookmark.Text = " ";

Document attached.

Thanks,
Stanislav

Hi Stanislav,

Thanks for your query. I have tested the scenario and have not found any issue with Bookmark.Text Property while using latest version of Aspose.Words for .NET. Please use the latest version of Aspose.Words for .NET. I have attached the output document file with this post.

Document doc = new Document(MyDir + "temp1.doc");
Aspose.Words.Bookmark AddendumBookmark = doc.Range.Bookmarks["START36634100479726875000F"];
AddendumBookmark.Text = " ";
AddendumBookmark.Name = AddendumBookmark.Name + "_Changed";
doc.Unprotect();
doc.Save(MyDir + "AsposeOut.doc");

Please let us know if you have any more queries.

Hi,

Thank you for the answer. I checked the problem again and like in my previous post the scenario when it happens a little bit more complex that i thought from the begginning:

Document mDocument = new Aspose.Words.Document(DocFileName);
Bookmark AddendumBookmark = mDocument.Range.Bookmarks["START36634100479726875000F"];
Bookmark AddendumSignatureBookmark = mDocument.Range.Bookmarks["START37634100479856406250F"];

AddendumSignatureBookmark.Text = " ";

AddendumBookmark.Text = " ";

Last row will throw exception: Parent cannot be null.

Thank you,
Stanislav.

Hi Stanislav,

Thanks for your query. You are facing this exception because one bookmark is inside the second bookmark. If you set the text of first bookmark, this will set the second bookmark’s test as empty string. I have also explained this same issue at following forum thread.

https://forum.aspose.com/t/51332

Please let us know if you have any more queries.