469,344 Members | 6,114 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,344 developers. It's quick & easy.

How to read a Doc or PDF file

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
Nov 15 '05 #1
5 9693
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

Nov 15 '05 #2
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


Nov 15 '05 #3
"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
Nov 15 '05 #4

"phoenix" <pa******@skynetWORK.be> schreef in bericht
news:Oz**************@TK2MSFTNGP12.phx.gbl...
"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


If the document is rather large you may think about opening it the same way
as above but saving it immediatly in rtf format. You can then open it
through your richtextbox. After you made the changes you can always use the
same way to overwrite the original doc if that's what you're planning.

Yves
Nov 15 '05 #5
Thanks Mate

Its a perfect solution. Thanks a lot

I am still toying the idea how can i read the content off PDF

Thanks once again

regards

Shayer
"phoenix" <pa******@skynetWORK.be> wrote in message
news:#a**************@TK2MSFTNGP12.phx.gbl...

"phoenix" <pa******@skynetWORK.be> schreef in bericht
news:Oz**************@TK2MSFTNGP12.phx.gbl...
"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


If the document is rather large you may think about opening it the same

way as above but saving it immediatly in rtf format. You can then open it
through your richtextbox. After you made the changes you can always use the same way to overwrite the original doc if that's what you're planning.

Yves

Nov 15 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Yang Li Ke | last post: by
10 posts views Thread by ZafT | last post: by
4 posts views Thread by ESPN Lover | last post: by
8 posts views Thread by a | last post: by
5 posts views Thread by lovecreatesbea... | last post: by
6 posts views Thread by Thomas Kowalski | last post: by
9 posts views Thread by flebber | last post: by
2 posts views Thread by Kevin Ar18 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.