We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Replace linking Word document inside footer containing bookmark

We copy content all linking Word documents inside source Word document

Aspose.Words.Document sourceDoc = new Aspose.Words.Document(source);
Aspose.Words.NodeCollection shapes = sourceDoc.GetChildNodes(NodeType.Shape,true);
foreach (Shape shape in shapes)
{
if (shape.OleFormat != null)
{
if (shape.OleFormat.IsLink)
{
if (shape.OleFormat.ProgId ==“Word.Document.8”)
{
Aspose.Words.Document LinkedDoc = new Aspose.Words.Document(shape.OleFormat.SourceFullName);
DocumentBuilder builder = new DocumentBuilder(sourceDoc);
builder.MoveTo(shape);
builder.InsertDocument(LinkedDoc, ImportFormatMode.KeepSourceFormatting);
}
}
}
}

Then remove all linking document shapes

There was bookmark inside linking document inside footer named ‘BookmartName’ for example.

After our procedure we have two Bookmarks : ‘BookmartName’ and ‘BookmartName_0’

But we need only ‘BookmartName’.

@fdmitry

Thanks for your inquriy. You may remove “BookmarkName_0” using following code snippet. However, if there is any difference in your requirement and our understanding then please share following resources here, we will look into these and will guide you accordingly.

.....
Bookmark bookmark = doc.Range.Bookmarks["Bookmark1"];
bookmark.Text="";
bookmark.Remove();
...
  • Your input Word document
  • Your output document showing undesired behavior
  • Your expected output document, you may use MS Word to create it.
  • Sample working console application(code without any compilation error) to replicate the issue at our end

Our document contains two different footers for the first and second page with linked files contained bookmarks of the same name. After conversion by aspose.word the second bookmark was named bookmark_0. It is correct. Topic is closed.

Thank you for your answer.

@fdmitry

Thanks for your feedback. It is good to know that you have managed to resolve issue at your own.

Please keep using our API and feel free to contact us for any further assistance.

Best Regards,