Mimic the document insertion feature (-inline) of the LINQ Reporting Engine with `DocumentBuilder.InsertDocument`

I have been trying unsuccessfully to find a way to replace a string within a paragraph with the content of another document, while mimicking the behavior of <<doc [document_expression] -inline>>.
I would prefer not to have to replace the desired string in advance with the document tag in order to use the reporting engine.

@kvaak Unfortunately, there is no built-in way to mimic the behavior using InsertDocumentMethod. I have logged a feature request for this as WORDSNET-25505.
However, you can use the following code to avoid insertion of a paragraph break after the inserted document content:

Document doc = new Document(@"C:\Temp\in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);

// Move to bookmark on the inline level
// Insert document.
builder.InsertDocument(new Document(@"C:\Temp\src.docx"), ImportFormatMode.UseDestinationStyles);
// Get the last paragraph from the inserted document.
Paragraph current = builder.CurrentParagraph;
Paragraph prev = (Paragraph)current.PreviousSibling;
// copy content from the current paragraph into the previouse paragraph and remove it.
while (current.HasChildNodes)


in.docx (12.3 KB)
src.docx (12.2 KB)
out.docx (9.7 KB)


@alexey.noskov I have to thank you once again for a very prompt response. Really good work. The example provided in the response is definitely a great solution. Thank you very much. Nevertheless, I am looking forward to a possible implementation of the feature request. Wishing you a great start to the week.

1 Like

The issues you have found earlier (filed as WORDSNET-25505) have been fixed in this Aspose.Words for .NET 23.10 update also available on NuGet.

1 Like