Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem saving the OLE Object to file

Status
Not open for further replies.

harmmeijer

Programmer
Mar 1, 2001
869
CN
I am using Access 97, one person has been and will be using access 97 forms to update and add records in the Access 97 tables.
The rest of the office is using an asp page to search and view the data in these tables.

The problem is that there are OLE Object fields in the tables. When a user wants to view these fields (mostly word documents) from an asp page the user should be presented with a href pointing to the file.
The file is located in the table as an OLE Object and I try to get it out using ADODB.Recordset and ADODB.Stream.
The file in the OLE Object field is not the same as the Word document that has been put in, Access adds some sort of OLE header (OLE head ache) to it.
How can I use asp (VB script or VB in MTS COM component) to get this file out, and put it on the IIS server as a physical file?
 
Still no answer, I'm starting to suspect that Access is not very good.
Anybody tried to update linked SQL server tables from an access form
Especially OLE object (image) or memo (ntext text) fields are LOL.
 
I can see that tek tips has changed last input, "not very good" was not exactly how I expressed my appriciation of ms access 97.

So in my opinion when you have an access database that needs to go to SQL server it is best to just forget all about access and rewrite the entire interface in asp.
 
Do you use the response.binarywrite method? It works very well for JPGs and GIF so it should work with .DOCs as well.
 
The point is that people have been putting in the OLE objects using Access forms.
This means thant Access has changed the document.
Using binaryWrite works if you remove the headers.
I had some code for viewing a bitmat, this code checks for the first carakters wich every bitmap contains.
This code works.
Too bad though Access puts some binary data before, inside and after the document.

If I know how to remove this info I can binarywrite or savetofile what is left.
 
Yipiiiiiiiiii, this is it. I can get the word document out.
In this case I saved it to file but the str can allso be used for binarywrite method of the response object (str.read)
The file which comes out is a lot bigger then the file going in but when opened in word you can read it.
With this word document I only removed the header not anything which comes after the doc.
With the pdf file I had to remove both head and tail.
Here is the code:
Sub putoutpdf()
Dim rs As New ADODB.Recordset
Dim str As New ADODB.Stream
Dim strChunk As String
Dim lngBegin As Long
Dim lngEnd As Long
Dim lngTemp As Long
rs.Open "SELECT * FROM TABLE1", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\test\load image.mdb;Persist Security Info=False", adOpenDynamic, adLockOptimistic
strChunk = StrConv(rs.Fields("pic"), vbUnicode)
Open "c:\test\aa.txt" For Output As #1
Print #1, strChunk ' for test purpose to see what is actually in the ole field converted to unicode
Close #1
lngBegin = InStrB(1, strChunk, "%PDF", vbTextCompare) ' this is the start of the pdf but instrb returns byte position need to do \2
lngTemp = 1
Do Until lngTemp = 0
lngTemp = InStrB(lngTemp + 1, strChunk, "%EOF", vbTextCompare) ' looking for the last %eof to determine the end of the pdf (access puts binary data before and after the ole field) instrb returns the byte position hence the \ 2
If lngTemp > 0 Then
lngEnd = lngTemp
End If
Loop
lngBegin = lngBegin \ 2
lngEnd = lngEnd \ 2
rs.Fields("pic").GetChunk (lngBegin)
str.Open
str.Type = adTypeBinary
str.Write rs.Fields("pic").GetChunk(rs.Fields("pic").ActualSize - (rs.Fields("pic").ActualSize - lngEnd))
str.SaveToFile "c:\test\eruit.pdf", adSaveCreateOverWrite
End Sub

Sub putoutdoc()
Dim rs As New ADODB.Recordset
Dim str As New ADODB.Stream
Dim strChunk As String
Dim lngBegin As Long
Dim lngEnd As Long
Dim lngTemp As Long
rs.Open "SELECT * FROM TABLE1", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\test\load image.mdb;Persist Security Info=False", adOpenDynamic, adLockOptimistic
strChunk = StrConv(rs.Fields("pic"), vbUnicode)
Open "c:\test\aa.txt" For Output As #1
Print #1, strChunk
Close #1
lngBegin = InStrB(1, strChunk, "ÐÏ", vbTextCompare) ' this is the start of the doc but instrb returns byte position need to do \2
lngTemp = 1
lngBegin = lngBegin \ 2
rs.Fields("pic").GetChunk (lngBegin) ' remove the header
str.Open
str.Type = adTypeBinary
str.Write rs.Fields("pic").GetChunk(rs.Fields("pic").ActualSize - (lngBegin))
str.SaveToFile "c:\test\eruit.doc", adSaveCreateOverWrite
End Sub


 
Is there a solution to get the same for word files and without the use of VB cause I have no permission to register dlls on my server.
What string signals that word data is starting?
is there sth like the %pdf for word???
 
Tried to extract plain word data with asp but without knowing what the ole header looks like its quite hard
 
You can use the Word with Access wizard ( page) to store the Docs in your MDB. This wizard leaves the OLE header unchanged and therefore you can use the binarywrite method which does not require any DLL on the web server.
 
A word document begins with the following:
ÐÏ

You can try the Sub putoutdoc() in my prefious input, thisone is to get the doc out.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top