I need some help here with list formatting. Suppose I have a document with a numbered list ( say 1,2,3 ). There’s a bookmark in the next line where a new paragraph should be added. I need to add that paragraph numbered as 4. Again, the numbered bullets ( i.e. 1,2,3 or so on ) might contain sub-lists again. But I want the paragraph being added numbered based on the main numbered list ( in this case, 4 )
NOTE: Attaching source and destination doc for reference.
Thanks for your inquiry. Please check following code snippet to add a numbered list from existing list. Hopefully it will help you to accomplish the task.
Document doc = new Document("Source.docx");
Paragraph listpara = null;
foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
if (listFormat.ListLevelNumber == 0)
listpara = para;
int listid = listpara.ListFormat.List.ListId;
List currentList = doc.Lists.GetListByListId(listid);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToBookmark("AddBookMarkHere", true, false);
builder.ListFormat.List = currentList;
builder.Writeln("New List paragraph");