Add items to (numbered) List

Hi!

I’ve got the requirement to find a (StructuredDocumentTag) placeholder that is attachet to a list and replace/fill it with 1-n list items.
Formatting of the surrounding list should be preserved.

It should be possible to start with only 1 item (for formatting purposes) but also to have some fixed items and add additional ones in between.

I figured out how to locate and handle the StructuredDocumentTags, but how do i add new list items?
For better understanding i attached 2 example files.

Thanks in advance

Hi Hans,

Thanks for your inquiry. We are checking with this scenario and will get back to you soon.

Best Regards,

Hi Hans,

Thanks for your inquiry. Yes, you can insert paragraph list items in StructuredDocumentTag. Please use following code snippets for your requirements. Hope this helps you. Please let us know if you have any more queries.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create list.
List list = doc.Lists.Add(ListTemplate.NumberDefault);
Paragraph para = new Paragraph(doc);
Run run = new Run(doc, "This is the first item");
para.AppendChild(run);
para.ListFormat.List = list;
Paragraph para2 = new Paragraph(doc);
run = new Run(doc, "This is the second item");
para2.AppendChild(run);
para2.ListFormat.List = list;
StructuredDocumentTag sdt1 = new StructuredDocumentTag(doc, SdtType.RichText, MarkupLevel.Block);
doc.FirstSection.Body.AppendChild(sdt1);
sdt1.Tag = "sdt1";
sdt1.RemoveAllChildren();
sdt1.AppendChild(para);
sdt1.AppendChild(para2);
doc.Save(MyDir + "AsposeOut.docx");

===========================================================

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create list.
List list = doc.Lists.Add(ListTemplate.NumberDefault);
builder.CurrentParagraph.ListFormat.List = list;
builder.Writeln("This is the first item");
builder.Write("This is the second item");
StructuredDocumentTag sdt1 = new StructuredDocumentTag(doc, SdtType.RichText, MarkupLevel.Block);
doc.FirstSection.Body.AppendChild(sdt1);
sdt1.Tag = "sdt1";
builder.MoveTo(sdt1.FirstChild);
builder.CurrentParagraph.ListFormat.List = list;
builder.Writeln("This is the third item");
builder.Write("This is the fourth item");
doc.Save(MyDir + "AsposeOut.docx");