F
Frostillicus
I'm trying to get an ASP to return a zip file to the remote browser from an
Image (BLOB) field in SQL Server 2000 but Internet Explorer keeps saying:
Cannot open C:\Documents and Settings\Frostillicus\Local Settings\Temporary
Internet Files\Content.IE5\U7GXENGF\file[1].zip
The URL to open the zip file is like this: doc_view.asp?id=1&ver=2
....where id and ver represent the zip file's version in the database. The
code I've pieced together to return the zip file is as follows (note: this
code works fine for PDF, JPG, DOC, XLS, GIF, and all sorts of files - just
not zip - HOWEVER, if I click "save" instead of "open" in the download box
then open the zip file manually, it works fine - Internet Explorer just
won't load WinZip for me automatically)
<% @language="VBScript" %>
<!-- #include file="./include/adovbs.inc" -->
<%
Response.Buffer = True
Response.Clear
Set RS = Server.CreateObject("ADODB.Recordset")
SQL = "SELECT ContentTypeString, DocumentData, DocumentTitle, FileExtension,
DocumentContentLength FROM DocumentVersion "
SQL = SQL & "WHERE (DocumentID = " & id & ") AND (VersionNumber = " & ver &
")"
Set RS = DbConn.Execute(SQL)
If Not RS.EOF Then
Response.ContentType = RS(0)
' zip file needs to be 1 byte more for some silly reason
If Not RS(0) <> "application/zip" Or Not RS(0) <>
"application/x-zip-compressed" Then
Response.AddHeader "Content-Length", RS(4) + 1
Else
Response.AddHeader "Content-Length", RS(4)
End If
Response.AddHeader "Content-Disposition", "filename=" & RS(2) & "." &
RS(3)
Response.BinaryWrite RS(1)
If Not RS(0) <> "application/zip" Or Not RS(0) <>
"application/x-zip-compressed" Then
Response.Write vbCrLf
End If
End If
RS.Close
Set RS = Nothing
Response.Flush
%>
The conscientious among us might say "what's the extra vbCrLf being printed
for, then"? Well, without the final carriage return I get a corrupt zip file
that is at least capable of being repaired. I have no idea why I need the
last carriage return but I decided to stick it in there after I saw (using
HTTP Watch to spy on the headers received) that the same zip file downloaded
via a normal hyperlink was one byte larger than the same zip file being
served up from the database (the binary data saved to the database is the
same length as the content-length for the normal hyperlinked zip file). So,
when I get the download-file box in Internet Explorer, if I click "Save"
then open the zip file manually, it works just fine.
If I click "Open", I get the nasty error message mentioned at the beginning
of this prolix post :-( I am tearing my hair out because this sort of thing
just ain't supposed to be this god-damned difficult. I mean, it's just a
stream of binary data and I'm sending the correct content types. What is so
special about Zip files?
Image (BLOB) field in SQL Server 2000 but Internet Explorer keeps saying:
Cannot open C:\Documents and Settings\Frostillicus\Local Settings\Temporary
Internet Files\Content.IE5\U7GXENGF\file[1].zip
The URL to open the zip file is like this: doc_view.asp?id=1&ver=2
....where id and ver represent the zip file's version in the database. The
code I've pieced together to return the zip file is as follows (note: this
code works fine for PDF, JPG, DOC, XLS, GIF, and all sorts of files - just
not zip - HOWEVER, if I click "save" instead of "open" in the download box
then open the zip file manually, it works fine - Internet Explorer just
won't load WinZip for me automatically)
<% @language="VBScript" %>
<!-- #include file="./include/adovbs.inc" -->
<%
Response.Buffer = True
Response.Clear
Set RS = Server.CreateObject("ADODB.Recordset")
SQL = "SELECT ContentTypeString, DocumentData, DocumentTitle, FileExtension,
DocumentContentLength FROM DocumentVersion "
SQL = SQL & "WHERE (DocumentID = " & id & ") AND (VersionNumber = " & ver &
")"
Set RS = DbConn.Execute(SQL)
If Not RS.EOF Then
Response.ContentType = RS(0)
' zip file needs to be 1 byte more for some silly reason
If Not RS(0) <> "application/zip" Or Not RS(0) <>
"application/x-zip-compressed" Then
Response.AddHeader "Content-Length", RS(4) + 1
Else
Response.AddHeader "Content-Length", RS(4)
End If
Response.AddHeader "Content-Disposition", "filename=" & RS(2) & "." &
RS(3)
Response.BinaryWrite RS(1)
If Not RS(0) <> "application/zip" Or Not RS(0) <>
"application/x-zip-compressed" Then
Response.Write vbCrLf
End If
End If
RS.Close
Set RS = Nothing
Response.Flush
%>
The conscientious among us might say "what's the extra vbCrLf being printed
for, then"? Well, without the final carriage return I get a corrupt zip file
that is at least capable of being repaired. I have no idea why I need the
last carriage return but I decided to stick it in there after I saw (using
HTTP Watch to spy on the headers received) that the same zip file downloaded
via a normal hyperlink was one byte larger than the same zip file being
served up from the database (the binary data saved to the database is the
same length as the content-length for the normal hyperlinked zip file). So,
when I get the download-file box in Internet Explorer, if I click "Save"
then open the zip file manually, it works just fine.
If I click "Open", I get the nasty error message mentioned at the beginning
of this prolix post :-( I am tearing my hair out because this sort of thing
just ain't supposed to be this god-damned difficult. I mean, it's just a
stream of binary data and I'm sending the correct content types. What is so
special about Zip files?