Here, I am going to share how we can read
paragraphs from a Microsoft Word Documnet using Microsoft.Office.Interop.Word
DLL.
1. Add reference of Microsoft.Office.Interop.Word DLL into your project
2. With the help of following class, we can read a specific paragraph of a MS
Word Document.
class WordDocReader
{
//To read paragraph contents of a Word document using Microsoft.Office.Interop.Word DLL
public string ReadFileContent(string path, int paraGraphNum)
{
int i = 0;
StringBuilder sb = new StringBuilder();
Microsoft.Office.Interop.Word.ApplicationClass wordApp = new ApplicationClass();
object file = path;
object nullobj = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open
(ref file, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj);
Microsoft.Office.Interop.Word.Paragraphs DocPar = doc.Paragraphs;
// Count number of paragraphs in the file
long parCount = DocPar.Count;
// Step through the paragraphs
while (i < parCount)
{
i++;
if (i == paraGraphNum)
{
sb.Append(DocPar[i].Range.Text);
break;
}
}
doc.Close(ref nullobj, ref nullobj, ref nullobj);
wordApp.Quit(ref nullobj, ref nullobj, ref nullobj);
return (sb.ToString());
}
}

MOHAMMED ABDUL SUBHANPosted May 2, 2017, 5:42 AM
I'm not getting the correct paragraph count..
Avinash PawarPosted Mar 8, 2016, 11:15 PM
i want paragraph count using open xml please help me
Mukesh KumarPosted Nov 24, 2015, 5:09 AM
Good One
Linga ReddyPosted Aug 22, 2014, 6:28 AM
I'm using same thing as mentioned above but the file is getting opened while getting the count. How can we restrict that