List Numbers not showing up

I’m trying to create a numbered list, but the numbers are not showing up. What am I missing? First, I setup the doc and doc builder:

Aspose.Words.Document doc = new Aspose.Words.Document(Path.Combine(templateFilePath, ioFileName));

var builder = new Aspose.Words.DocumentBuilder(doc);

var bookmark = doc.Range.Bookmarks["recs"];
Aspose.Words.Lists.List list = null;

if (Constants.UseCaseTypeRecContinuousNumbering)
{
	list = doc.Lists.Add(Aspose.Words.Lists.ListTemplate.NumberArabicDot);
	list.ListLevels[0].NumberStyle = Aspose.Words.NumberStyle.Arabic;
	list.ListLevels[0].NumberPosition = 0;
	list.ListLevels[0].TextPosition = 20;
	list.ListLevels[0].TabPosition = 20;

}
else
{
	list = doc.Lists.Add(Aspose.Words.Lists.ListTemplate.BulletDefault);
}

Then I iterate over some data points and add a new list item for each one (there’s some omitted code here that does the iterating and also decides if a grouping header needs to also be inserted)

Aspose.Words.Paragraph recPara = new Aspose.Words.Paragraph(doc);
recPara.ParagraphFormat.StyleIdentifier = Aspose.Words.StyleIdentifier.Normal;				
bookmark.BookmarkStart.ParentNode.ParentNode.InsertBefore(recPara, bookmark.BookmarkStart.ParentNode);

Aspose.Words.Section thisSection = GetParentSection(recPara);
var sectionParas = thisSection.GetChildNodes(Aspose.Words.NodeType.Paragraph, true);
builder.MoveToParagraph(sectionParas.IndexOf(recPara), 0);
builder.ListFormat.List = list;
builder.InsertHtml(rec.RecText);
recPara.ParagraphFormat.LeftIndent = 70;

The list seems to be getting made, as it’s indented the way that I want, but there is neither a bullet nor a number for each list item being added

Thanks

Hello
Thanks for your inquiry. Could you please create simple application, which will demonstrate the problem on my side? I will check it and provide you more information.
Best regards,

ok, attached a project with all the pertinent stuff included. Thanks for looking into it

Hi Jason,
Thanks for your inquiry.
When you insert content from HTML the formatting is taken explicty from the HTML and not from the DocumentBuilder. Therefore currently you need to use
and
tags in your HTML snippets to make the inserted content have bullet points.
In your case since you want to apply formatting from the DocumentBuilder you should just use the Writeln method with your plain text instead. Please see the modified code below.

string[] listItems = new string[]{
    "First Item",
    "Second Item",
    "Last Item"
    };
builder.MoveTo(bookmark.BookmarkStart);
foreach (var rec in listItems)
{
    builder.ListFormat.List = list;
    builder.CurrentParagraph.ParagraphFormat.LeftIndent = 70;
    builder.Writeln(rec);
}
bookmark.BookmarkStart.ParentNode.Remove();
doc.Save("output.docx");

Thanks,

Adam,
Thanks for your help, but that answer doesn’t really get me to my goal. I did stumble on a happy workaround though. If you append any character to your HTML, the InsertHTML() function preserves the Numbered List formatting (found this out when I attempted to write out the numbering manually; this resulted in the numbers being duplicated as in “1. 1. stuff”).


That coupled with a little regex to kill the paragraph tags (which were causing the indentation to get out of whack) ended up solving my problem. I’ll post the code below, which allows us to build a continuously numbered list, based on HTML user inputs (ckeditor) and grouped by region headers:
Aspose.Words.Document doc = new Aspose.Words.Document("template.docx");
var builder = new Aspose.Words.DocumentBuilder(doc);
var bookmark = doc.Range.Bookmarks["recs"];
Aspose.Words.Lists.List list = null;
list = doc.Lists.Add(Aspose.Words.Lists.ListTemplate.NumberArabicDot);
list.ListLevels[0].NumberStyle = Aspose.Words.NumberStyle.Arabic;
list.ListLevels[0].NumberPosition = 0;
list.ListLevels[0].TextPosition = 20;
list.ListLevels[0].TabPosition = 20;

string[] listItems = new string[]{
	"<p>First Item </p> <p>With Some more stuff</p>",
	"<p>Second Item </p>",
	"<p>Last Item </p>"
};

Regex pTag = new Regex("<p>", RegexOptions.IgnoreCase);
Regex pEndTag = new Regex("</p>", RegexOptions.IgnoreCase);
foreach (var rawRec in listItems)
{
	//replace the P tags - this fixes the indentation getting reset within the list
	string rec = string.Empty;
	rec = pTag.Replace(rawRec, "");
	rec = pEndTag.Replace(rec, "\x0b"); //The MS Word character for new line - \r\n doesn't always work

	//add in a group header
	Aspose.Words.Paragraph headerPara = new Aspose.Words.Paragraph(doc);
	Aspose.Words.Run headerRun = new Aspose.Words.Run(doc);
	headerRun.Text = "The Form Name Here";
	headerPara.AppendChild(headerRun);
	bookmark.BookmarkStart.ParentNode.ParentNode.InsertBefore(headerPara, bookmark.BookmarkStart.ParentNode);
	//prep the paragraph that the rec item will go
	Aspose.Words.Paragraph recPara = new Aspose.Words.Paragraph(doc);
	recPara.ParagraphFormat.StyleIdentifier = Aspose.Words.StyleIdentifier.Normal;
	bookmark.BookmarkStart.ParentNode.ParentNode.InsertBefore(recPara, bookmark.BookmarkStart.ParentNode);
	Aspose.Words.Section thisSection = GetParentSection(recPara);
	var sectionParas = thisSection.GetChildNodes(Aspose.Words.NodeType.Paragraph, true);
	builder.MoveToParagraph(sectionParas.IndexOf(recPara), 0);
	builder.ListFormat.List = list;

	//append an empty string to the rec- this magically forces the numbered list to work. Any character will do, and this one is invisible
	builder.InsertHtml("&nbsp;" + rec);
	recPara.ParagraphFormat.LeftIndent = 70;

Here’s what my output looks like:Stuff

Your Recs:

The Form Name

  1. First Item
    With Some more stuff

The Form Name

  1. Second Item
    The Form Name

  2. Last Item
    Recs

Other stuff
Thanks

Hello Jason,
Thank you for additional information. Your HTML contains
tags. The text between these tags is represented as separate paragraphs after inserting HTML. So if would like to insert HTML into the list item (list item is a paragraph in Word document) you should avoid using tags which are represented as paragraphs after inserting HTML. This is not a bug this is expected behavior.
Best regards,