473,473 Members | 1,482 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 9868
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Yang Li Ke | last post by:
Hi guys! I have some datas that I must check everytime a visitor comes to my site What is better to do: 1- Read data from a file or 2- Read data from a mysql db Thank you
10
by: ZafT | last post by:
Thanks in advance for any tips that might get me going in the right direction. I am working on a simple exercise for school that is supposed to use read to read a file (about 10 MB). I am...
1
by: cnu | last post by:
My program generates a log file for every event that happens in the program. So, I open the file and keep it open till the end. This is how I open the file for writing: <CODE> public...
4
by: ESPN Lover | last post by:
Below is two snippets of code from MSDN showing how to read a file. Is one way preferred over the other and why? Thanks. using System; using System.IO; class Test { public static void...
8
by: a | last post by:
I have a struct to write to a file struct _structA{ long x; int y; float z; } struct _structA A; //file open write(fd,A,sizeof(_structA)); //file close
5
by: lovecreatesbea... | last post by:
The condition at line 31 is added to check if the program finished to read the whole file. Is it needed and correct? Thank you. #include <fstream> #include <iostream> #include <string> using...
0
by: lovecarole | last post by:
hi, i am the student who should write a program about reading wav file and do the DFT. actually i don't know how to read data of the wav song and save it into the array... if i want to read...
6
by: Thomas Kowalski | last post by:
Hi, currently I am reading a huge (about 10-100 MB) text-file line by line using fstreams and getline. I wonder whether there is a faster way to read a file line by line (with std::string line)....
9
by: flebber | last post by:
I was working at creating a simple program that would read the content of a playlist file( in this case *.k3b") and write it out . the compressed "*.k3b" file has two file and the one I was trying...
2
by: Kevin Ar18 | last post by:
I posted this on the forum, but nobody seems to know the solution: http://python-forum.org/py/viewtopic.php?t=5230 I have a zip file that is several GB in size, and one of the files inside of it...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.