LINQ Reporting C# .NET | Foreach & IF on Same Line on Numbered List | Word IF Tag > False Adds Paragraph Break with List Numbering

Some items have sub-items I want to display beneath the parent item. Like this:

1. Item without sub item
2. Item with sub item
   baz
3. Item without sub item

But this code:

1. <<foreach [in Data[“Foo”]]>><<[[“Text”]]>><<if [[“Bar”].Any()]>>
   baz<</if>>
<</foreach>>

removes the numbers on items without sub items:

   Item without sub item
1. Item with sub item
   baz
   Item without sub item

How can I achieve it?

@TobiasWalter,

Please ZIP and attach the following resources here for testing:

  • Your simplified template Word document
  • Aspose.Words 20.11 generated output DOCX document showing the undesired behavior
  • A standalone simple Console application (source code without compilation errors) that helps us to reproduce your current problem on our end and attach it here for testing. Please do not include Aspose.Words DLL/JAR files in it to reduce the file size.
  • Your expected DOCX file showing the desired output. You can create this document manually by using MS word.

As soon as you get these pieces of information ready, we will start further investigation into your scenario/issue and provide you more information.

Here you go. Happy testing!

AsposeBugExample.zip (54.8 KB)

@TobiasWalter,

We have logged this problem in our issue tracking system. Your ticket number is WORDSNET-21496. We will further look into the details of this problem and will keep you updated on the status of the linked issue. We apologize for any inconvenience.

@TobiasWalter,

Regarding WORDSNET-21496, this is an expected behavior rather than a bug. Syntax used in the template makes the engine to remove a Paragraph Break containing List numbering information when the if tag evaluates to false. However, there is a simple way to fix this by changing the syntax. Please check template-modified.zip (10.9 KB).

Hello @awais.hafeez,

thank you for your reply. Your fix fixes the numbering, but introduces an empty line on items where <<if [Bar != null]>> evaluates to null. I get the following result when I try your solution:

1. Item without sub item

2. Item with sub item
   baz
3. Item without sub item


Is it possible to get rid of the new line for items without Bar?

It seems that I was wrong. It works now! Thank you!!!

@TobiasWalter,

It is great that you were able to find what you were looking for. We have now closed the linked issue (WORDSNET-21496). Please let us know any time you may have any further queries in future.