Solved

Reading from Document file

Posted on 2004-04-27
10
170 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
Comment Utility
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
Comment Utility
0
 

Author Comment

by:shivab
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:shivab
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

13 Experts available now in Live!

Get 1:1 Help Now