Update HTML inserted using documentBuilder.InsertHtml() method

I am trying to insert HTML in my word document. I am able to do it. The problem is every time I use this method it appends the HTML content after the bookmark. My requirement is to replace the existing HTML(overwrite the content). Here is the code I am using:

Document wordDoc = new Document(@"D:\Projects\Aspose\Template.docx");
var bookmark = wordDoc.Range.Bookmarks["b_Edtions"];


wordDoc.Range.Bookmarks[bookmark.Name].Text = string.Empty;
var documentBuilder = new Aspose.Words.DocumentBuilder(wordDoc);
if (documentBuilder.MoveToBookmark(bookmark.Name, true, true))
{
    string html_output = "<b>Dynamic HTML</b>";
    documentBuilder.InsertHtml(html_output);
    wordDoc.Save(@"D:\Projects\Aspose\TemplateFinal.docx");
}

Attaching document used in the above code.
Template.docx (49.0 KB)

@zafarsultan As I can see your code properly inserts content inside bookmark:

The same is seen if explore document’s structure:

Hi @alexey.noskov,

The code above works fine. What I am looking for is a way if I can replace the existing HTML. In other words I need to update the HTML rather than insert HTML. The above code “Inserts” the HTML so if there is already HTML content the new content will be appended to the document. I need to replace the existing HTML.

@zafarsultan Your code does exactly this by removing old bookmark’s content and inserting new content inside bookmark using InsertHtml method.