Replace Bookmark in One Document From another

I hope you have shared the same code available in GitHub

I want them in extract content also

@Raghul214 As i have mentioned the provided code is the modified implementation of ExtractContentHelper that takes sections into account.

Yes @alexey.noskov But Its not working for extracting content of header and footer…

In the validation your giving

if (startNode.GetAncestor(NodeType.Body) == null || endNode.GetAncestor(NodeType.Body) == null)
    throw new ArgumentException("Start node and end node must be a child or descendant of a body");

How will that work?

@Raghul214 The code demonstrates technique of extracting content. It is supposed to extract content from the document’s main body. The condition checks whether start and end nodes are in the document’s main body.

Which means its won’t work with header and footer correct?

@Raghul214 No, the code will not work for extracting content from header/footer.

Then what is the way for that…?
Is there any way to extract the content of Header footer Bookmark

@Raghul214 You can remove the above condition and add another condition to check whether start and end nodes are in the same story, i.e. in the main body or in the same header/footer.

other than that everything will work…?

What I mean only the validation will change all other code remain as or I have to modify

@Raghul214 The provided code demonstrates the basic technique for extracting content between nodes. You are free to modify the code according to your needs.
By the way, you can easily extract content from header/footer by copying the header/footer content into the main body of empty document and then extract content from the main body of the temporary document.

Yes even I taught of that approach But since you have suggested this I wanted to clarify

1 Like