I guess you can't do it using FindUniqueByPattern
or FindAll
. Newline is not represented by any symbol but stored as a paragraph with empty text. You can peek document representation in xml format from document.Xml
property, there you'll see empty line stored as single <w:p>
element.
Therefore you can search for Paragraphs with empty text instead of searching for newline character :
using (DocX document = DocX.Load(filename))
{
var emptyLines = document.Paragraphs.Where(o => string.IsNullOrEmpty(o.Text));
foreach (var paragraph in emptyLines)
{
paragraph.Remove(false);
}
document.Save();
}