Free Support Forum - aspose.com

Issue with copying Bookmark range from a source document to a target document

I'm having an issue copying the range for a bookmark from one document to another (I also posted the same issue to an older thread I started some time back). What happens is that if the bookmark contains multiple lines of text, then the last line is not copied to the target document. When I debug, I see why this is happening, but can't find a way to fix it.

Below is my code (almost exactly like code an Aspose member previously suggested); can someone take a look at see why this doesn't work? Any suggestions would be greatly appreciated.

// This method is used to export a bookmark to a document.
private void ExportBookmarkToDocument(Bookmark bookmark, ref Aspose.Words.Document targetDocument)
{
// Get node that containd BookmarkStart and BookmarkEnd
Node currentNode = bookmark.BookmarkStart.ParentNode;
Node endNode = bookmark.BookmarkEnd.ParentNode;

// If bookmarkStart and bookmarkEnd are children of different nodes
// Then import nodes between parent nodes of bookmark start and bookmark end
if (currentNode != endNode)
{
//Import nodes between BookmarkStart and BookmarkEnd Parent nodes
while (currentNode != endNode)
{
Node newNode = targetDocument.ImportNode(currentNode, true, ImportFormatMode.KeepSourceFormatting);targetDocument.FirstSection.Body.AppendChild(newNode);
currentNode = currentNode.NextSibling;
}
}

// Else import nodes between bookmark start and bookmark end
else
{
currentNode = bookmark.BookmarkStart.NextSibling;

//Import nodes between BookmarkStart and BookmarkEnd
while (currentNode != bookmark.BookmarkEnd)
{
Node newNode = targetDocument.ImportNode(currentNode, true, ImportFormatMode.KeepSourceFormatting);
targetDocument.FirstSection.Body.FirstParagraph.AppendChild(newNode);
currentNode = currentNode.NextSibling;
}
}
}

Thanks in advance!

-Jafar

Hi

Thanks for your request. This question is already answered in <A href="https://forum.aspose.com/t/110925</A></P> <P> </P> <P>Best regards,</P>