We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Deleting paragraph that contains specific text in word document


I have a word template, with tables and fields set inside bookmarks.
There is an issue on some places when bookmarks are adjacent, line under line which creates an error on finding bookmarkEnd.
I managed to solve that by inserting paragraph of text in between.
Now I would like to remove all paragraphs in document, at the end before file is exported.
Paragraphs contain word "break" so I need to search and remove all those paragraphs.
Also it would be helpful to be able to remove(delete) previous and next empty paragraph if it is possible.

2 Replies

CM Cubrilo Milos April 25, 2017 06:42 AM UTC

Solved with Syncfusion documentation -> File Formats -> DocIO -> Working with Word document

Only modification I had to make is instead of deleting it in an loop, to put paragraph indexes in a list and then after looping through the whole document reverse the list and delete all the indexes backwards, because in other case I would get index out of range exception.

Hope this helps someone.

SR Suganya Rathinam Syncfusion Team April 25, 2017 10:25 AM UTC

Hi Cubrilo

Thank you contacting Syncfusion support.

We have prepared a sample to find the paragraph with specified text and remove that particular paragraph from the document using Find functionality of DocIO. Please find the sample from the following link and let us know if it helps.

Sample link

Things done in the sample:
1. Remove the paragraph with the specified text from the document.
2. Remove the empty paragraphs before and after the paragraph with the specified text from the document.

Please let us know if you need any further assistance.

Suganya R

Live Chat Icon For mobile
Up arrow icon