We uses FileStream to read text from text file, but We have to use Microsoft’s COM component called as “Microsoft Word 11.0 Object Library”, which provides classes and Methods to perform operation with Word Document.
From Add Reference Choose COM tab and Select “Microsoft Word 11.0 Object Library”.
We uses Word.ApplicationClass to perform read operation with Word Document.
The code is given below.
private void ReadWordDoc()
{
Word.ApplicationClass wordApp = new Word.ApplicationClass();
// File Path
string strFilePath = “E:/TestRead.doc”;
// Create obj filename to pass it as paremeter in open object objFile = strFilePath;object objNull = System.Reflection.Missing.Value;
object objReadOnly = true;//Open DocumentWord.Document Doc = wordApp.Documents.Open(ref objFile, ref objNull, ref objReadOnly, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull);
// To read each line consider each line as paragraph Docuemnt
int i = 1;
foreach (Word.Paragraph objParagraph in Doc.Paragraphs)
{
try {lblName.Text += Doc.Paragraphs[i].Range.Text;
}catch (Exception ex){throw ex;}i++;
} // close document and Quit Word ApplicationDoc.Close(ref objNull, ref objNull, ref objNull);
wordApp.Quit(ref objNull, ref objNull, ref objNull);
}
Benazir
Hi,
Thanks for this submission.
Hello!!
It works perfectly!
But, when I have a Doc which contains a selector or advanced form, for example multiple selector box,
how can I capture those varaibles??
thanks!
Hello
Glad that you gave a solution, but the requirement for me is that , i want to preserve the formatting of the word document.
how can i achieve the same
thanx in advance
Sandhya
thank you alot it made alot of help for me
hello it is test. WinRAR provides the full RAR and ZIP file support, can decompress CAB, GZIP, ACE and other archive formats.
klqxslpmjlyreuzxguumxlcnyuiuwtaffrahello