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

Free Support Forum - aspose.com

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;
        <span style="color:blue;">if</span> (section != <span style="color:blue;">null</span>)
        {
            section.InsertBefore(...
        }<br><br>Is FirstSection in an document, which is created from html always the body ?<br>Or should I "search" the body  ? <br><br>but how to use the insertbefore if the body doesn't have any tags ?<br><br>And is there also an way to format the inserted text, like "ForeColor = Blue"  ?<br></pre><pre style="font-family:Consolas;font-size:13;color:black;background:white;">So whats the best practice?<br></pre>

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);

builder.InsertHtml(
“Text Before Body

Paragraph right

” +

Implicit paragraph left” +
Div center
” +

Heading 1 left.

”);


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 ?

Hi

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:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/aspose.words.documentbuilder.movetodocumentstart.html

Hope this helps.

Best regards,