Skip to main content
A newer version of this page is available. .

How to: Create Bulleted List in Code

  • 2 minutes to read

This example illustrates how to create a standard bulleted list in code.

  1. Add a new AbstractNumberingList instance to the Document.AbstractNumberingLists collection
  2. Specify a NumberingListBase.NumberingType property, so that it equals the NumberingFormat.Bullet value.
  3. For each list level, specify the paragraph characteristics using the ListLevel.ParagraphProperties property. Set the left indentation (the ParagraphPropertiesBase.LeftIndent property) so that each level has a different offset from the left. To specify a symbol that will be used to mark a list item, set the font via the ListLevel.CharacterProperties property and the character via the ListLevelProperties.DisplayFormatString property.
  4. Use the Add method of the collection of lists in the document (accessible via the Document.NumberingLists property) to add a list definition to the document. The parameter is the index of an abstract numbering list created previously. The Add method creates a pattern that can be applied to a paragraph so that the paragraph looks like a list item.
  5. To include a paragraph in a bulleted list, set the Paragraph.ListIndex property of a paragraph to the index of a list in the document and specify the Paragraph.ListLevel property.
Document document = server.Document;
document.BeginUpdate();
// Define an abstract list that is the pattern for lists used in the document.
AbstractNumberingList list = document.AbstractNumberingLists.Add();
list.NumberingType = NumberingType.Bullet;

// Specify parameters for each list level.

ListLevel level = list.Levels[0];
level.ParagraphProperties.LeftIndent = 100;
level.CharacterProperties.FontName = "Symbol";
level.DisplayFormatString = new string('\u00B7', 1);

// Create a list for use in the document. It is based on a previously defined abstract list with ID = 0.
NumberingList bulletedList = document.NumberingLists.Add(0);
document.EndUpdate();

document.AppendText("Line 1\nLine 2\nLine 3");
// Convert all paragraphs to list items.
document.BeginUpdate();
ParagraphCollection paragraphs = document.Paragraphs;
paragraphs.AddParagraphsToList(document.Range, bulletedList, 0);

document.EndUpdate();