Aspose word copy bookmark

Hi,

I have 2 word documents which have same bookmark names. I would like to transfer first document’s (name is ‘eskiDoc.doc’) bookmark, which has same name (‘BaskiResmi’) with other document’s bookmark, to second document (name is ‘yeniDoc.doc’). For this, we use this code below. But it isn’t working. We need your help.
Thanks
My best regards

                foreach (Aspose.Words.Bookmark bookmark in eskiDoc.Range.Bookmarks)
                {
                    Aspose.Words.Bookmark yenibookmark = yeniDoc.Range.Bookmarks[bookmark.Name];
                    if (yenibookmark!=null)
                    {
                        yenibookmark.Text = bookmark.Text;
                    }
                }

aspose.zip (302.4 KB)

@srmbimser

Thanks for your inquiry. There is no content in the bookmark (BaskiResmi) in your document. Could you please share your expected output document here for our reference? We will then provide you with more information about your query.

eskidoc.PNG (35.9 KB)
yenidoc.PNG (61.7 KB)

Hi,

As we pointed out in the pictures above, we are trying to print the value in the value of eskidoc.png to yenidoc.png.
Thanks

@srmbimser

Thanks for sharing the detail. The bookmark contains no content. The image is after the bookmark. Please check the attached image for detail. Bookmark is a “facade” object that encapsulates two nodes BookmarkStart and BookmarkEnd in a document tree and allows to work with a bookmark as a single object.

To get the desired output, please use the following code example. Hope this helps you.

Document eskiDoc = new Document(MyDir + "eskidoc.doc");
Document yeniDoc = new Document(MyDir + "yenidoc.doc");

NodeImporter imp = new NodeImporter(eskiDoc, yeniDoc, ImportFormatMode.KeepSourceFormatting);

foreach (Aspose.Words.Bookmark bookmark in eskiDoc.Range.Bookmarks)
{
    Aspose.Words.Bookmark yenibookmark = yeniDoc.Range.Bookmarks[bookmark.Name];
    if (yenibookmark != null)
    {
        //yenibookmark.Text = bookmark.Text;
                        
        foreach (Node node in bookmark.BookmarkStart.ParentNode)
        {
            Node impNode = imp.ImportNode(node, true);
            yenibookmark.BookmarkStart.ParentNode.AppendChild(impNode);
        }
    }
}