Free Support Forum -

Error generating report when Section Break is included in a <<foreach>> loop

When a Section Break is present inside a ‘foreach’ loop, the following error is generated:

Tag ‘foreach’ is not well-formed. Can not copy or remove document contents between different stories or cells of different tables

​foreach [p in Properties]
​===============Section Break==============

I was wondering if anyone came across this issue, and if so, how you managed to get around it. Removing the Section Break is not always an ideal solution, since there are instances when I need the Section Break so it separates single column pages from multi-column ones.

Any help would be greatly appreciated.



Thanks for your inquiry. LINQ Reporting Engine does not support section breaks within foreach tags. However, for LINQ Reporting Engine, there is the following way to declare a page break inside a foreach tag. Hope this helps you.

DocumentBuilder builder = new DocumentBuilder();
builder.Write("<<foreach [in items]>>");
builder.Write("Page #<<[NumberOf()]>>");

ReportingEngine engine = new ReportingEngine();

ArrayList items = new ArrayList();
for (int i = 0; i < 3; i++)
    items.Add(new object());

engine.BuildReport(builder.Document, items, "items");

Hi Tahir,

Thank you for getting back to me.
Although the solution provided may work from a Document.Builder perspective, it won’t address my problem since the Section Break is already defined in a pre-built Word document template.
At the same time I would like to understand if there is a technical reason why the Section Breaks don’t work within foreach tags. In case there isn’t a technical barrier, it would be great if this can be accommodated as an enhancement in future versions of Aspose.Words.

Many thanks,


Thanks for your inquiry. The LINQ Reporting Engine does not support section breaks within foreach tags by analogy with classic mail merge. Your template should be according to LINQ Reporting syntax.

Could you please share the complete detail of your use case along with input and expected output documents? We will then log this feature in our issue tracking system accordingly.

Hi Tahir,

Many thanks for your investigation and apologies for the delay in getting back to you.
As requested I have attached to this case a Word template input containing a typical foreach loop with a couple of section breaks in between.
Additionally you will see a word template containing what should be the correct output data.

We appreciate if this could be raised with your product team as a feature request.
Would be great if you could let me have a reference number for the new feature too.


Error generating report when Section Break is included in a <> (30.2 KB)


Thanks for sharing the detail. We have logged this feature request as WORDSNET-17026 in our issue tracking system. We will look into the possibility of implementation of this feature and will inform you via this forum thread once there is any update available on it.

1 Like