How to InsertHtml as a proper bulleted list

Hi I have an issue with Aspose.Words using Visual Basic where I’m inserting data programmatically from a table in SQL. I have a block of HTML that I am inserting that needs to have a new bullet each line.
The current simple code I am using:

Dim oBuilder As New DocumentBuilder(oDoc)
'Retrieve Item to be inserted'
oBuilder.ParagraphFormat.StyleIdentifier = StyleIdentifier.ListBullet
oBuilder.InsertHtml(Item.ToString, True)

But as a result, I am only getting the first line bulleted such as below. Presumably because the text is being entered all at once?

  • Item 1
    Item 2
    Item 3
    Item 4

Any solutions would be greatly appreciated. If needed I could create a sample word document, but I don’t think it would add any value.

@SethD02 Could you please provide HTML code of your items here for testing? We will check and provide you more information.

<b>Item 1</b> <br /> <b>Item 2</b> <br /> <b>Item 3</b> <br /> <b>Item 4</b>

@alexey.noskov

Sorry how do I include the HTML code without it automatically formatting into text haha

EDIT: Nevermind I figured it out and posted it above

@SethD02 <br /> tag is imported as a soft line break (Shift+Enter) and does not produce a list bullet, since all text is in the same paragraph. In your case you can split your items into separate strings and insert them like this:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

string html = "<b>Item 1</b> <br /> <b>Item 2</b> <br /> <b>Item 3</b> <br /> <b>Item 4</b>";

builder.ListFormat.ApplyBulletDefault();

foreach (string item in html.Split(new string[] { "<br />" }, StringSplitOptions.RemoveEmptyEntries))
{
    builder.InsertHtml(item);
    builder.Writeln();
}

builder.ListFormat.RemoveNumbers();

doc.Save(@"C:\Temp\out.docx");

@alexey.noskov My mistake, works perfectly! Thank you for your help

1 Like