"Shayer" <sh*******@hotmail.com> schreef in bericht
news:e0**************@TK2MSFTNGP09.phx.gbl...
Thanks for ur advice
But how can i open the doc and read the content and display in the
richtextbox
How can u do that
ANy sample code will be helpful
Thanks
regards
Shayer
"phoenix" <pa******@skynetWORK.be> wrote in message
news:OO**************@TK2MSFTNGP10.phx.gbl... Docs and pdfs have special layouts. You'll need specific readers for
that. You can open your Doc using word then selecting all text and copy it to
your richtextbox. For pdfs I never tried it but I guess there's something
similar.
Yves
"Shayer" <sh*******@hotmail.com> schreef in bericht
news:uD**************@tk2msftngp13.phx.gbl... Hello All
I am trying to read a MSDoc file and PDF file using Streamreader and
then display the content into a richtext box. But cant do that.
Anyone can pls help me out
Thanks
Shayer
First of all add a reference to the word library. It should be located under
'COM' under 'Microsoft Word x.xx Object Library' (with x.xx your version).
Then the following code should do the trick :
/*************************************************/
object filename = @"c:\test.doc";
object save = false;
object oMissing = System.Reflection.Missing.Value;
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = false;
// Open word document
// different versions of word may have more or less oMissings
oDoc = oWord.Documents.Open(ref filename, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing);
// Select everything
oDoc.Select();
// Copy everything
oWord.Selection.Copy();
// Clean up the RTB
richTextBox1.Text = "";
// Paste the entire text with format
richTextBox1.Paste();
// Close word
oDoc.Close(ref save, ref oMissing, ref oMissing);
oWord.Quit(ref save, ref oMissing, ref oMissing);
/*************************************************/
HTH
Yves