We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to Remove Empty Paragraphs from the Document using .NET

How to delete a blank row without deleting a shape?Attachment documents is sourceFile.Docx and targetFile.docx,In the targeFile, I marked it with a red figure.I use code:

if(paragraph.ToString(Aspose.Words.SaveFormat.Text) == "\r\n")
    p.Remove();

This code also removes shape, which is not what I want.

Desktop.zip (410.2 KB)

@lovecomputer

Please use following code example to get the desired output. Hope this helps you.

Document doc = new Document(MyDir + "sourceFile.doc");

foreach (Paragraph paragraph in doc.GetChildNodes(NodeType.Paragraph, true))
{
    if (paragraph.GetChildNodes(NodeType.Shape, true).Count == 0
        && paragraph.ToString(SaveFormat.Text).Trim().Length == 0)
        paragraph.Remove();
}
doc.Save(MyDir + @"21.7.doc");