Hi,
When trying to write an value in a bookmark we get the error “Start and end node should have the same grand parent”.
We are using Aspose.Words.dll version 6.3.0.
Here’s a code snippet that we use to update a bookmark:
public static byte[] UpdateBookmark(byte[] document, string bookmark, string value)
{
Licences.RegisterAspose();
using(MemoryStream memoryStream = new MemoryStream(document))
{
ZorroDocument doc = new ZorroDocument(memoryStream as Stream);
if (doc.Builder.MoveToBookmark(bookmark, true, false))
doc.Range.Bookmarks[bookmark].Text = value;
doc.Save(memoryStream, SaveFormat.Doc);
}
return document;
}
I attached an example of a document we use.
Regards,
Louis
Hi
Thanks for your inquiry. I managed to reproduce the problem on my side. Your request has been linked to the appropriate issue, you will be notified as soon as it is fixed. It seems the reason of the problem is SmartTag. So as a workaround you can try using the following code:
Document doc = new Document("000510701-003.doc");
doc.RemoveSmartTags();
After removing smart tags all works fine.
But you should note, RemoveSmartTags method is available starting from 8.0.0 version. But in older versions you can also remove SmartTags, for example you can try using the following code:
///
/// Removes all SmartTYag nodes from the document, preserving content
///
/// Input document
public void RemoveSmartTags(Document doc)
{
// Get collection of SmartTags from the document
NodeCollection nodes = doc.GetChildNodes(NodeType.SmartTag, true, true);
// Loop while there is SmartTags in the document
while (nodes.Count> 0)
{
SmartTag tag = (SmartTag) nodes[0];
// Get parent node of smartTag.
// we should move all content from smatrTag to its parent to preserve documents content
CompositeNode parent = tag.ParentNode;
// Loop through all nodes inside smartTag and move its convent to parent node
while (tag.HasChildNodes)
parent.InsertBefore(tag.FirstChild, tag);
// Remove smartTag
tag.Remove();
}
}
Hope this helps.
Best regards,
Hi Andrey,
Thanx for your reply.
Good to hear you can reproduce the issue. We can only reproduce the issue in our production environment, not in our development environment. Can you share how you reproduced the issue?
Thanx.
Regards,
Louis
Hi Louis,
Thanks for your request. There were no problems to reproduce the issue. The following simple code allows us to reproduce the problem:
doc.Range.Bookmarks["ArtStartDate"].Text = "Test";
We will let you know once the issue is resolved.
Best regards,
Just that simple.Thanks Alexey.
The issues you have found earlier (filed as WORDSNET-4691) have been fixed in this .NET update and this Java update.
This message was posted using Notification2Forum from Downloads module by aspose.notifier.