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

Free Support Forum - aspose.com

LINQ Reporting Engine - Inserting documents in a foreach loop

Is it possible to use nested doc includes in a foreach loop?

eg:

List of Persons:
•	<<foreach [in Persons]>> <<doc [doc1] -build>>
<</foreach>>

Where the included Template Document has the defined layout of a person

<<[Name]>>, <<[Surname]>>

In my test the doc1-Document is not rederred in the context of the person (foreach). It renderes always the first person.

@studs0815

It seems like this happens because you pass the same Aspose.Words.Document instance (that is, doc1) in a doc tag expression all the time. So, on the first iteration, a template is filled with data and then (since it contains no tags at this point) this filled document is used on subsequent iterations.

To avoid this from happening, you can use the following options:

  1. Given that my assumtion is correct and doc1 stands for a Document instance, you can use the following doc tag instead: <<doc [doc1.Clone()] -build>>. This will guarantee a separate Document instance is used for every iteration.

  2. You can also use other options for passing document data such as a byte array or string as per the following article: Inserting Documents Dynamically. This will cause loading of a new document on every iteration.