Search Text & Delete Paragraphs from DOCX Word Document using C# .NET API


I need to delete all recurrences of the text shown below(including the paragraph break at the end) from a document:

Blank line to be deleted^q

Attached a zip file contains an input and output sample files: (20.4 KB)

Can someone help please?


You can meet this requirement by using the following code of Aspose.Words for .NET:

Document doc = new Document("E:\\Temp\\PragraphBreak\\Input.docx");

ArrayList list = new ArrayList();
foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
    if (para.ToString(SaveFormat.Text).Trim().Contains("***Blank line to be deleted***"))

for (int i = 0; i < list.Count; i++)