Update TOC using openxml

Home Forums Open-Xml-Sdk Update TOC using openxml

This topic contains 0 replies, has 1 voice, and was last updated by  kumarm 3 years, 8 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #8852

    kumarm
    Participant

    hi Eric,

    i have gone through your blog and tried the below approach to update the tOCs of a document. the document has the TOCs already but seems to be not working.
    could you please help me out where i was going wrong.

    Code used
    using (WordprocessingDocument document = WordprocessingDocument.Open(localFilePath,true))//@”C:\Users\MAKTHKU1\Downloads\TocAdder-1\TocAdder\TOC\bin\Debug\netcoreapp3.1\CEMA401A2202 Protocol v00.docx”, true))
    {

    var settingsPart =
    document.MainDocumentPart.GetPartsOfType<DocumentSettingsPart>().First();
    settingsPart.Settings = new Settings { BordersDoNotSurroundFooter = new BordersDoNotSurroundFooter() { Val = true } };
    settingsPart.Settings.Append(new UpdateFieldsOnOpen() { Val = true });
    settingsPart.Settings.Save();
    document.Save();
    }

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.