Remove a header/section and content while preserving others in a word document for C#?

I am using the Asp.net DOCIO functions of Syncfusion, ingesting in a document. I want to find a specific heading/header and delete all the content in that header only. I have attached a example of a document I would want to take in, and for this example, I would want to remove the section 2 header and all content under it – while preserving the section 1 and section 3 headers and content.


Is this possible? I’ve been having trouble coming up with a solution, and if you have any insight, it would be greatly appreciated!


Attachment: example_to_remove_header_dde54f42.zip

1 Reply

SR Sindhu Ramesh Syncfusion Team March 13, 2025 02:25 PM UTC

Hi Sydney,
Based on the details provided, we understand that your requirement is to remove content from a Word document. To achieve this, you can insert a bookmark in the document for the content you wish to delete. Using DocIO, you can retrieve the bookmark with BookmarksNavigator and delete its content from the document.
We have modified the input document by inserting a bookmark for the content we wish to delete. Kindly refer the attached modified input document along with output document.

Kindly refer the below GitHub sample for implementation:
Delete-bookmark-content

If your requirement is different, please share the expected output document. We will review it and provide a suitable solution to achieve your requirement.

For more detailed information about working with bookmarks, kindly refer to the below user guide
Working with Bookmarks in .NET Word library | Syncfusion

Regards,
Sindhu Ramesh.


Attachment: example_to_remove_header_5eacd36e.zip

Loader.
Up arrow icon