Free Support Forum -

How to drop a section completely from a document


Could you please provide a sample code to drop completely (delete full content) a section?

Request is to delete a section if it contains text "#DELETE_SECTION#".

Input document and desired output document are attached.

Best regards, Evgeniy

Hi Evgeniy,

Thanks for your inquiry. Please use the following code snippet to be able to delete the whole Section that contains your specific filter text:

Document doc = new

foreach (Section sec in doc.Sections)

if (sec.Range.Text.Contains("#DELETE_SECTION#"))



I hope, this helps.

Best Regards,

Hi Awais,

Thank you very much for the solution! This works.

Best regards, Evgeniy

Hi Evgeniy,

Thanks for your feedback. Please let us know any time you have any further queries. We’re always glad to help you.

Best Regards,