Free Support Forum - aspose.com

How to move cursor after using InsertDocument function

Hi:

I have a function that populates a word template. It has code that uses the InsertDocument() of Aspose.Words to take content from another word document and insert it into the current. The problem I'm having is, after it does the insert - when I do a builder.Write("print out some text"), the text does not print after the inserted content since the inserted content only contains images with returns in between them...the printed text printed out in the first empty line instead of knowing where the end of the inserted contents are.

The code sample is below, is there a way to tell the cursor to go after the inserted content and then start printing?

Dim src As Aspose.Words.Document = New Aspose.Words.Document(something)

'Insert into this document

Utilities.InsertDocument(builder.CurrentParagraph, src)

builder.Write ("Message:) <-- this needs to print out after the inserted content

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. I think, you can try using code like the following to achieve this.

// Open documents

Document dst = new Document(@"Test001\dst.doc");

Document src = new Document(@"Test001\src.doc");

// Create docuent builder and move to the appropriate location.

DocumentBuilder builder = new DocumentBuilder(dst);

builder.MoveToBookmark("test");

// Now insert paragraph break.

builder.Writeln();

// And insert source document before inserted paragrapg.

InsertDocument(builder.CurrentParagraph.PreviousSibling, src);

// Insert some text after the inserted document.

builder.Write("This text will be inserted after the inserted document.");

// Save output document.

dst.Save(@"Test001\out.doc");

Hope this helps.

Best regards.

It works! Thank you so much!