Solved

Reading from Document file

Posted on 2004-04-27
10
175 Views
Last Modified: 2010-04-24
Hi,
How can i read from doc file(for example word files)? I want wirte file content to a databse field.
thanks,
0
Comment
Question by:shivab
  • 4
  • 3
10 Comments
 
LVL 27

Expert Comment

by:Dabas
ID: 10928592
Hi shivab:
First step is to add a Word Com object to your references
To do so, right click on References in Solution explorer, then choose Add Reference...
A dialog comes up with three tabs on it. Click on the COM Tab
Scroll down until you see an entry whose name starts with Microsoft Word
Click on Select
Click on OK.

You now have a reference to the Word library.
If you go to the object browser, you will see all its methods and properties.

Hope this gets you started!


Dabas
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 10928902
0
 

Author Comment

by:shivab
ID: 10929791
I don't want open doc files.I want to write doc text to databse for searching.
I have done this for htm files as below:

Dim oneChar As Char
FileOpen(1, openFileDialog1.FileName, OpenMode.Input)
While Not EOF(1)
   oneChar = (InputString(1, 1))
   Content = Content + oneChar
End While
FileClose(1)

This code doesn't work for word files because they are in binary mode.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:Dabas
ID: 10929962
shivab:
> This code doesn't work for word files because they are in binary mode.
That is why you need to open the doc file through COM!
Alternatively, you could in Word (or through Com) save your word file as HTML, then use your code as above.

Dabas
0
 

Author Comment

by:shivab
ID: 10970764
Dear Dabas,
I found solution For reading Binary files like word documnets.I used the LOF and Loc functions instead of EOF when reading binary file as below:

 Dim oneChar As Char
 FileOpen(1, openFileDialog1.FileName, OpenMode.Binary)
 Len = LOF(1)
 While Loc(1) < len
         oneChar = (InputString(1, 1))
         If Asc(oneChar) >= 32 And Asc(oneChar) <= 125  Then
               FileContent = FileContent + oneChar.ToString()
         End If
 End While
 FileClose(1)

and then i insert FileContent to Database.

Avish,
0
 
LVL 27

Accepted Solution

by:
Dabas earned 125 total points
ID: 10971041
shivab:
Not a bad idea. Essentially you are stripping all control characters (<32)
I am not so sure about the 125 and above. There are quite a lot of characters that are in use, specially if the document should have foreign words, or even special symbols such as the ² (square) sign (Chr(253))
On the other hand, Word might use a combination of a smaller than Chr(32) character together with another character to mean something special, in which case your conversion would not work. (Often Escape Chr(27) is used in combination with a "Clean" character, so do not be sure your solution is foolproof!
I would still go for COM.

Dabas
0
 

Author Comment

by:shivab
ID: 10993153
Dabsa,
I am going to search in text of file then i want charachters between 32 , 125 only.
My problem was solved.thanks all.
shiva,
0
 
LVL 27

Expert Comment

by:Dabas
ID: 10993170
shivab,
I am glad your problem was solved.
What my last post was about is that if you want to use this same method in the future then there is a possibility that it will fail for the reasons stated.


Dabas
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

761 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question