Solved

Reading from Document file

Posted on 2004-04-27
10
173 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
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

810 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