shivab
asked on
Reading from Document file
Hi,
How can i read from doc file(for example word files)? I want wirte file content to a databse field.
thanks,
How can i read from doc file(for example word files)? I want wirte file content to a databse field.
thanks,
ASKER
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.
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.
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
> 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
ASKER
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,
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,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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,
I am going to search in text of file then i want charachters between 32 , 125 only.
My problem was solved.thanks all.
shiva,
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
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
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