using Word = Microsoft.Office.Interop.Word;
try
{
object oMissing = System.Type.Missing;
Word.Application wordApp = new Word.Application();
Microsoft.Office.Interop.Word.Paragraphs paragraphs = null;
Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(ref wordPath, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
doc.Activate();
paragraphs = doc.Paragraphs;
foreach (Word.Paragraph paragraph in paragraphs)
{
if (paragraph.Range.Text.Trim() == string.Empty)
{
paragraph.Range.Select();
wordApp.Selection.Delete();
}
}
}catch (Exception)
{
}
finally
{
if (doc != null)
{
((_Document)doc).Close(ref oMissing, ref oMissing, ref oMissing);
Marshal.FinalReleaseComObject(doc);
}
if (wordApp != null)
{
((_Application)wordApp).Quit();
Marshal.FinalReleaseComObject(wordApp);
}
}