Free Support Forum - aspose.com

Inserting a document into the current document

Hello.

I would like to insert an external Word document into the document I’m generating.

I have something like this:

// I generate paragraphs in the main document
builder.Writeln();
builder.builder.InsertParagraph();
...

// Here I want to insert the document. So I create a new paragraph and I call the InsertDocument
// function (described in the Aspose documentation)
Document doc = new Document("Test.doc");
Node insertAfterNode = (Node)builder.InsertParagraph();
InsertDocument(insertAfterNode, doc);

// Then I continue generating other paragraphs
builder.builder.InsertParagraph();
...

The InsertDocument works fine, but the Test.doc document is appended to the end of the main document and not at the position I want.

Can you tell me want I'm doing wrong ?
Do you have an example ?

Thanks
Regards
Augusto

Hi

Thanks for your inquiry. I think that you should insert builder.MoveToDocumentEnd();after inserting the document.

InsertDocument(insertAfterNode, doc);

builder.MoveToDocumentEnd();

// Then I continue generating other paragraphs
builder.builder.InsertParagraph();

I hope this could help you.

Best regards.

Hello Alexey.

It works fine with the MoveToDocumentEnd method !

Thanks for your help.
Regards
Augusto