We may have used FileStream to read text from a text file but not the same way for getting text from a word document. We have to use Word.ApplicationClass to have access to the word application. Word.ApplicationClass wordApp=new ApplicationClass(); object file=path; object nullobj=System.Reflection.Missing.Value; 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); doc.ActiveWindow.Selection.WholeStory(); doc.ActiveWindow.Selection.Copy(); IDataObject data=Clipboard.GetDataObject(); txtFileContent.Text=data.GetData(DataFormats.Text).ToString(); doc.Close(); |
|