Insert a text at the begin / end of an HTML Body

What is the best / most efficient way to insert a short text at the begin / end of a body?

My Idea is something like that :

var section = doc.FirstSection;
if (section != null )

Is FirstSection in an document, which is created from html always the body ?
Or should I “search” the body ?

but how to use the insertbefore if the body doesn’t have any tags ?

And is there also an way to format the inserted text, like “ForeColor = Blue” ?
So whats the best practice?

Hi Boas,

Please use the following code snippet to insert a short text at the beginning of body. Please read the documentation of DocumentBuilder class. Let me know, If you have any further queries.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

    "Text Before Body<body><P align='right'>Paragraph right</P>" +
    "<b>Implicit paragraph left</b>" +
    "<div align='center'>Div center</div>" +
    "<h1 align='left'>Heading 1 left.</h1></body>");

doc.Save("d:\\DocumentBuilder.InsertHtml Out.doc");

Thx for your reply. I Understand the befit of documentbuilder.

But I can’t see how I can locate the beginning and ending of the body of an existing document.

Or will Inserthtml ensure that my content is inserted at the beginning of the body ?

Thanks for your request. You can use DocumentBuilder.MoveToDocumentStart and DocumentBuilder.MoveToDocumentEnd methods to move its cursor to the beginning or to the end of a document appropriately. Please follow the link for more information:
Hope this helps.
Best regards,