Solved

Reading from Document file

Posted on 2004-04-27
10
172 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
A short film showing how OnPage and Connectwise integration works.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

930 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now