Below code will read the content of a Microsoft Word document and return the text in a string variable.
public string GetText()
{
string Referees = string.Empty;
string totaltext = "";
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
object miss = System.Reflection.Missing.Value;
object path = Server.MapPath("~/Content/Documents/CV March 2013 Peter Corbitt.docx");
object readOnly = true;
Microsoft.Office.Interop.Word.Document docsw = word.Documents.Open(ref path, ref miss, ref readOnly, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);
try
{
for (int i = 0; i < docsw.Paragraphs.Count; i++)
{
totaltext += " \r\n " + docsw.Paragraphs[i + 1].Range.Text.ToString();
}
docsw.Close();
word.Quit();
}
catch (Exception ex)
{
docsw.Close();
word.Quit();
throw ex;
}
return totaltext;
}
Thursday, September 26, 2013
How to Read MS Word Document Content using Office Interoperability Service Assemblies
Subscribe to:
Post Comments (Atom)
No comments:
Write comments