Extract text under a specific heading

I need to extract the text under a specific heading.

word document example:

Afbakening

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis,

  • List item

  • List item

  • List item

  • List item

another heading

this is text i do not need to extract




So the text under the heading “afbakening” needs to be extracted.

It would be even better if someone knows how to extract only the list items as strings under that specific heading.

@kits

In your case, we suggest you please use the following code example to get the list items under heading text. Hope this helps you.

Document doc = new Document(MyDir + "input.docx");
NodeCollection paras = doc.GetChildNodes(NodeType.Paragraph, true);
ArrayList list = new ArrayList();
Boolean blnStart = false;
foreach (Paragraph paragraph in paras.OfType<Paragraph>())
{
    if (paragraph.ParagraphFormat.IsHeading && paragraph.ToString(SaveFormat.Text).Trim() == "afbakening")
    {
        blnStart = true;
    }

    if (paragraph.ParagraphFormat.IsHeading && paragraph.ToString(SaveFormat.Text).Trim() == "afbakening")
    {
        blnStart = false;
        break;
    }

    if (blnStart && paragraph.ParagraphFormat.IsListItem)
    {
        list.Add(paragraph);
    }
}

foreach (Paragraph para in list)
{
    Console.WriteLine(para.ToString(SaveFormat.Text));
}