Hi Anthony,
we us IIS 5.0
Thanks for your suggestion. I do have include file, but it has nothing about
buffer set up, no html code, only database connection include file. And I
went to IIS virtual direcotry and saw default configuration for the
application is "enable buffer", so I unchecked this option and it no longer
complains the statement "Response.Buffer = false ".
My pdf file is not big at all, it's less than 90KB. Now after I changed the
code, it gives me very informational error message like this:
Response object error 'ASP 0156 : 80004005'
Header Error
/DeliverPdf.asp, line 48 'which is Response.ContentType =
"application/octet-stream"
The HTTP headers are already written to the client browser. Any HTTP header
modifications must be made before writing page content.
--'end of the eeror message
Then I thought it is because we have default HTTP headers in virtual
directoy, which is something generated by the system like this:
P3P: xxxxx
x-powered by: asp.net
Then I removed that default header and it still display the same error
message.
I don't get this.
My code is as follow:
----deleiverpdf.asp
<!--#INCLUDE VIRTUAL = "/utility/init_test.asp" -->
'init_test is database connection file
<html>
<%
cmdTemp.CommandText="a sql comand to fetch record from system based filename"
dim FileName, strFilePath
'Response.End
Set pdf_info = Server.CreateObject("ADODB.Recordset")
pdf_inf
pen cmdTemp, , adOpenKeyset, adLockOptimistic
If pdf_info.EOF Then
response.redirect "/noPicFound404.gif"
Else
pdf_info.MoveFirst()
'Response.Write "File Name: " & pdf_info("pdfFileName")
OK=False
If Request("FileName")=Trim(pdf_info("pdfFileName")) Then
strFilePath = Server.MapPath(pdf_info("TempPdfFilePath"))& "\" &
Request("FileName")
'Response.Write " Path " & strFilePath
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If CInt(pdf_info("MinElapsed")) < CInt(pdf_info("ExpTime")) then
OK=true
End If
If objFSO.FileExists(strFilePath) and OK Then
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1
objStream.LoadFromFile strFilePath
Response.Buffer = false
Response.ContentType = "application/octet-stream"
Response.AddHeader "Content-Type", "application/pdf"
Response.AddHeader
"Content-Disposition","inline;filename="&Request("FileName") %>
<body>
<%Response.BinaryWrite objStream.Read
Response.Flush
objStream.Close
Set objStream = Nothing
'Response.Write "I am inside pdf delivery."
Else
response.write "Sorry, the file doesn't exist."
End If
Set objFSO = Nothing
Response.end
End If 'End If FileName is the same as in the database system
End If 'End If pdf_info is EOF
'End Function
Response.Write FileName & "<br>"
Response.Write strFilePath & "<br>"
conn.Close
set conn=Nothing
cmdTemp.Close
set cmdTemp=Nothing
%>
</body>
</html>