Solved

Reading from Document file

Posted on 2004-04-27
10
177 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

631 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