Our Blog

DocX – Add nested lists to Microsoft Word document programmatically

If you had one of those days looking for solution on how to easily add a nested list to Microsoft Word document by using C# search no more. Below you can find an example on how to do that using DocX package.


Following prerequisites are required to create Microsoft Word document programmatically:

DocX package
Visual Studio 2013 / Visual Studio 2015 (Free Community Edition will do)
Basic understanding on how to code in C# (C Sharp)
Basic tutorial on how to start coding with DocX package can be found on our blog post DocX – A short tutorial for beginners HelloWorld()

Example code

Following code provides basic example on how to add Nested Lists to Microsoft Word programmatically.

Example Output

Code above should create an output file called Lists.docx. If you start it up the view should be showing nice Nested Lists.

Example Notes

Above example is part of DocX Examples and can be found in DocX source package under Examples \ Program.cs. This example uses RelativeDirectory.cs class. It's required for the code sample to work and are included in the sources of DocX.

Keep that in mind when working with the code to either download the DocX package or change the code appropriately. Below you can find Relative Directory class just in case you have no access to sources.

Tags: , , , , , ,

This is a unique website which will require a more modern browser to work! Please upgrade today!