Here is the code to read a word filr from our .net application.. we just need to add the com reference in our application
Add Reference >>> COM Tab >> MicroSoft office 11.0 object library..
Microsoft.Office.Interop.Word.ApplicationClass wordApp = new Microsoft.Office.Interop.Word.ApplicationClass(); object file = "D:\\Anil\\test\\testfile.doc"; // path for word file 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,ref nullobj, ref nullobj, ref nullobj, ref nullobj); doc.ActiveWindow.Selection.WholeStory(); doc.ActiveWindow.Selection.Copy(); IDataObject data = Clipboard.GetDataObject(); string allText = data.GetData(DataFormats.Text).ToString(); doc.Close(ref nullobj, ref nullobj, ref nullobj); wordApp.Quit(ref nullobj, ref nullobj, ref nullobj); Textbox1.Text = allText);
|
No responses found. Be the first to respond and make money from revenue sharing program.
|