We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Need code to insert paragraph after toc end field in word document

Hi awais,

I need code to add paragraph after toc end field and move builder to that newly added paragraph, then , my requirement is to insert section break on that newly created paragraph.

its urgent requirement, please help me get out from this problem.

Thanks,
Harish G


This Topic is created by awais.hafeez using Email to Topic tool.

It’s very urgent requirement for me. Please consider my request.

@HarishGali You can use code like the following to achieve this:

Document doc = new Document(@"C:\Temp\in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);

foreach (Field f in doc.Range.Fields)
{
    if (f.Start.FieldType == FieldType.FieldTOC)
    {
        builder.MoveToField(f, true);
        builder.Writeln();
        builder.InsertBreak(BreakType.SectionBreakNewPage);
    }
}

doc.Save(@"C:\Temp\out.docx");