Gibberish Pdf file displayed if I transfer using bit stream

Discussion in 'ASP General' started by c676228, Feb 9, 2007.

  1. c676228

    c676228 Guest

    Hi all,
    The following code was suggested by one of the users in this newsgroup when
    a pdf file was requested by a user from an asp page. I used the similar code
    in my page and the very interesting thing is when the pdf is displayed on the
    fly, the whole page is a gibberish code in stead of a normal pdf file. But it
    displays fine if I just use a link to a file on the page. Can you tell me
    what's the possible reason will cause this problem?
    Thank you.


    > 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/pdf"
    > Response.AddHeader "Content-Type", "application/pdf"
    > Response.AddHeader "Content-Disposition","inline;filename="&once
    > Response.BinaryWrite objStream.Read
    > Response.Flush
    > objStream.Close
    > Set objStream = Nothing
    > else
    > response.write "Sorry, nonexisting file"
    > end if
    > Set objFSO = Nothing
    > Response.end
    > end if


    --
    Betty
     
    c676228, Feb 9, 2007
    #1
    1. Advertising

  2. c676228

    c676228 Guest

    Oh, I forgot to tell you that I removed the code
    Response.Buffer = false
    since I set up this is true some where, it tells me that I cannot reset to
    false.
    So I removed that, not sure if this will impact on the result, I guess not?
    --
    Betty


    "c676228" wrote:

    > Hi all,
    > The following code was suggested by one of the users in this newsgroup when
    > a pdf file was requested by a user from an asp page. I used the similar code
    > in my page and the very interesting thing is when the pdf is displayed on the
    > fly, the whole page is a gibberish code in stead of a normal pdf file. But it
    > displays fine if I just use a link to a file on the page. Can you tell me
    > what's the possible reason will cause this problem?
    > Thank you.
    >
    >
    > > 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/pdf"
    > > Response.AddHeader "Content-Type", "application/pdf"
    > > Response.AddHeader "Content-Disposition","inline;filename="&once
    > > Response.BinaryWrite objStream.Read
    > > Response.Flush
    > > objStream.Close
    > > Set objStream = Nothing
    > > else
    > > response.write "Sorry, nonexisting file"
    > > end if
    > > Set objFSO = Nothing
    > > Response.end
    > > end if

    >
    > --
    > Betty
     
    c676228, Feb 9, 2007
    #2
    1. Advertising

  3. "c676228" <> wrote in message
    news:...
    > Hi all,
    > The following code was suggested by one of the users in this newsgroup

    when
    > a pdf file was requested by a user from an asp page. I used the similar

    code
    > in my page and the very interesting thing is when the pdf is displayed on

    the
    > fly, the whole page is a gibberish code in stead of a normal pdf file. But

    it
    > displays fine if I just use a link to a file on the page. Can you tell me
    > what's the possible reason will cause this problem?
    > Thank you.
    >
    >
    > > 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/pdf"
    > > Response.AddHeader "Content-Type", "application/pdf"
    > > Response.AddHeader "Content-Disposition","inline;filename="&once
    > > Response.BinaryWrite objStream.Read
    > > Response.Flush
    > > objStream.Close
    > > Set objStream = Nothing
    > > else
    > > response.write "Sorry, nonexisting file"
    > > end if
    > > Set objFSO = Nothing
    > > Response.end
    > > end if

    >


    Do you have other include files in the ASP code?
    Do you have other content that is being sent before this code?
    The inability to use Response.Buffer = false would indicate that you do.

    In the case above Response.Buffer = false in unnecessary since you write the
    complete contents of the stream to the response in one call to BinaryWrite.

    On IIS6 the default response buffer is 4MB so if your PDF is potentially
    larger you will either need to increase this limit or chunk out the PDF
    contents.

    This is my stock function for doing this:-

    Sub SendFileToResponse(FilePath, FileName)

    Const clChunkSize = 1048576 ' 1MB

    Dim oStream, i
    Response.Buffer = False

    Response.ContentType = "application/octet-stream"
    Response.AddHeader "Content-Disposition", _
    "Filename=" & FileName

    Set oStream = Server.CreateObject("ADODB.Stream")
    oStream.Type = 1 ' Binary
    oStream.Open
    oStream.LoadFromFile FilePath

    For i = 1 To oStream.Size \ clChunkSize
    Response.BinaryWrite oStream.Read(clChunkSize)
    Next
    If (oStream.Size Mod clChunkSize) <> 0 Then
    Response.BinaryWrite oStream.Read(oStream.Size Mod clChunkSize)
    End If
    oStream.Close

    End Sub

    You would call this function as:-

    SendFileToResponse strFilePath, once

    since it chunks out the content there is no need to worry about buffer size.
    However before you can use it you will need to look at what is happening
    earlier in your page that is already placing unwanted content in the
    response.

    Anthony.


    > --
    > Betty
     
    Anthony Jones, Feb 9, 2007
    #3
  4. c676228

    c676228 Guest

    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_info_Open 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>



    --
    Betty


    "Anthony Jones" wrote:

    >
    > "c676228" <> wrote in message
    > news:...
    > > Hi all,
    > > The following code was suggested by one of the users in this newsgroup

    > when
    > > a pdf file was requested by a user from an asp page. I used the similar

    > code
    > > in my page and the very interesting thing is when the pdf is displayed on

    > the
    > > fly, the whole page is a gibberish code in stead of a normal pdf file. But

    > it
    > > displays fine if I just use a link to a file on the page. Can you tell me
    > > what's the possible reason will cause this problem?
    > > Thank you.
    > >
    > >
    > > > 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/pdf"
    > > > Response.AddHeader "Content-Type", "application/pdf"
    > > > Response.AddHeader "Content-Disposition","inline;filename="&once
    > > > Response.BinaryWrite objStream.Read
    > > > Response.Flush
    > > > objStream.Close
    > > > Set objStream = Nothing
    > > > else
    > > > response.write "Sorry, nonexisting file"
    > > > end if
    > > > Set objFSO = Nothing
    > > > Response.end
    > > > end if

    > >

    >
    > Do you have other include files in the ASP code?
    > Do you have other content that is being sent before this code?
    > The inability to use Response.Buffer = false would indicate that you do.
    >
    > In the case above Response.Buffer = false in unnecessary since you write the
    > complete contents of the stream to the response in one call to BinaryWrite.
    >
    > On IIS6 the default response buffer is 4MB so if your PDF is potentially
    > larger you will either need to increase this limit or chunk out the PDF
    > contents.
    >
    > This is my stock function for doing this:-
    >
    > Sub SendFileToResponse(FilePath, FileName)
    >
    > Const clChunkSize = 1048576 ' 1MB
    >
    > Dim oStream, i
    > Response.Buffer = False
    >
    > Response.ContentType = "application/octet-stream"
    > Response.AddHeader "Content-Disposition", _
    > "Filename=" & FileName
    >
    > Set oStream = Server.CreateObject("ADODB.Stream")
    > oStream.Type = 1 ' Binary
    > oStream.Open
    > oStream.LoadFromFile FilePath
    >
    > For i = 1 To oStream.Size \ clChunkSize
    > Response.BinaryWrite oStream.Read(clChunkSize)
    > Next
    > If (oStream.Size Mod clChunkSize) <> 0 Then
    > Response.BinaryWrite oStream.Read(oStream.Size Mod clChunkSize)
    > End If
    > oStream.Close
    >
    > End Sub
    >
    > You would call this function as:-
    >
    > SendFileToResponse strFilePath, once
    >
    > since it chunks out the content there is no need to worry about buffer size.
    > However before you can use it you will need to look at what is happening
    > earlier in your page that is already placing unwanted content in the
    > response.
    >
    > Anthony.
    >
    >
    > > --
    > > Betty

    >
    >
    >
     
    c676228, Feb 9, 2007
    #4
  5. "c676228" <> wrote in message
    news:...
    > 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 ".


    I strongly recommend you turn that back on again.

    > 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>


    The above is part of the problem you've started to send html content but you
    want to send a pdf. Your page should only contain ASP code in <% %>. There
    should be no HTML mark up in it at all.

    > <%
    > 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_info_Open 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")


    Get rid of this bit of markup also

    %>
    > <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
    > %>


    And this bit as well:

    > </body>
    > </html>





    > --
    > Betty
    >
    >
    > "Anthony Jones" wrote:
    >
    > >
    > > "c676228" <> wrote in message
    > > news:...
    > > > Hi all,
    > > > The following code was suggested by one of the users in this newsgroup

    > > when
    > > > a pdf file was requested by a user from an asp page. I used the

    similar
    > > code
    > > > in my page and the very interesting thing is when the pdf is displayed

    on
    > > the
    > > > fly, the whole page is a gibberish code in stead of a normal pdf file.

    But
    > > it
    > > > displays fine if I just use a link to a file on the page. Can you tell

    me
    > > > what's the possible reason will cause this problem?
    > > > Thank you.
    > > >
    > > >
    > > > > 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/pdf"
    > > > > Response.AddHeader "Content-Type", "application/pdf"
    > > > > Response.AddHeader "Content-Disposition","inline;filename="&once
    > > > > Response.BinaryWrite objStream.Read
    > > > > Response.Flush
    > > > > objStream.Close
    > > > > Set objStream = Nothing
    > > > > else
    > > > > response.write "Sorry, nonexisting file"
    > > > > end if
    > > > > Set objFSO = Nothing
    > > > > Response.end
    > > > > end if
    > > >

    > >
    > > Do you have other include files in the ASP code?
    > > Do you have other content that is being sent before this code?
    > > The inability to use Response.Buffer = false would indicate that you do.
    > >
    > > In the case above Response.Buffer = false in unnecessary since you write

    the
    > > complete contents of the stream to the response in one call to

    BinaryWrite.
    > >
    > > On IIS6 the default response buffer is 4MB so if your PDF is potentially
    > > larger you will either need to increase this limit or chunk out the PDF
    > > contents.
    > >
    > > This is my stock function for doing this:-
    > >
    > > Sub SendFileToResponse(FilePath, FileName)
    > >
    > > Const clChunkSize = 1048576 ' 1MB
    > >
    > > Dim oStream, i
    > > Response.Buffer = False
    > >
    > > Response.ContentType = "application/octet-stream"
    > > Response.AddHeader "Content-Disposition", _
    > > "Filename=" & FileName
    > >
    > > Set oStream = Server.CreateObject("ADODB.Stream")
    > > oStream.Type = 1 ' Binary
    > > oStream.Open
    > > oStream.LoadFromFile FilePath
    > >
    > > For i = 1 To oStream.Size \ clChunkSize
    > > Response.BinaryWrite oStream.Read(clChunkSize)
    > > Next
    > > If (oStream.Size Mod clChunkSize) <> 0 Then
    > > Response.BinaryWrite oStream.Read(oStream.Size Mod clChunkSize)
    > > End If
    > > oStream.Close
    > >
    > > End Sub
    > >
    > > You would call this function as:-
    > >
    > > SendFileToResponse strFilePath, once
    > >
    > > since it chunks out the content there is no need to worry about buffer

    size.
    > > However before you can use it you will need to look at what is happening
    > > earlier in your page that is already placing unwanted content in the
    > > response.
    > >
    > > Anthony.
    > >
    > >
    > > > --
    > > > Betty

    > >
    > >
    > >
     
    Anthony Jones, Feb 9, 2007
    #5
  6. c676228

    c676228 Guest

    Hooray! Anthony,

    That works after I removed the html tag. Mm, I had another good lession.
    Thank you.
    --
    Betty


    "Anthony Jones" wrote:

    >
    > "c676228" <> wrote in message
    > news:...
    > > 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 ".

    >
    > I strongly recommend you turn that back on again.
    >
    > > 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>

    >
    > The above is part of the problem you've started to send html content but you
    > want to send a pdf. Your page should only contain ASP code in <% %>. There
    > should be no HTML mark up in it at all.
    >
    > > <%
    > > 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_info_Open 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")

    >
    > Get rid of this bit of markup also
    >
    > %>
    > > <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
    > > %>

    >
    > And this bit as well:
    >
    > > </body>
    > > </html>

    >
    >
    >
    >
    > > --
    > > Betty
    > >
    > >
    > > "Anthony Jones" wrote:
    > >
    > > >
    > > > "c676228" <> wrote in message
    > > > news:...
    > > > > Hi all,
    > > > > The following code was suggested by one of the users in this newsgroup
    > > > when
    > > > > a pdf file was requested by a user from an asp page. I used the

    > similar
    > > > code
    > > > > in my page and the very interesting thing is when the pdf is displayed

    > on
    > > > the
    > > > > fly, the whole page is a gibberish code in stead of a normal pdf file.

    > But
    > > > it
    > > > > displays fine if I just use a link to a file on the page. Can you tell

    > me
    > > > > what's the possible reason will cause this problem?
    > > > > Thank you.
    > > > >
    > > > >
    > > > > > 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/pdf"
    > > > > > Response.AddHeader "Content-Type", "application/pdf"
    > > > > > Response.AddHeader "Content-Disposition","inline;filename="&once
    > > > > > Response.BinaryWrite objStream.Read
    > > > > > Response.Flush
    > > > > > objStream.Close
    > > > > > Set objStream = Nothing
    > > > > > else
    > > > > > response.write "Sorry, nonexisting file"
    > > > > > end if
    > > > > > Set objFSO = Nothing
    > > > > > Response.end
    > > > > > end if
    > > > >
    > > >
    > > > Do you have other include files in the ASP code?
    > > > Do you have other content that is being sent before this code?
    > > > The inability to use Response.Buffer = false would indicate that you do.
    > > >
    > > > In the case above Response.Buffer = false in unnecessary since you write

    > the
    > > > complete contents of the stream to the response in one call to

    > BinaryWrite.
    > > >
    > > > On IIS6 the default response buffer is 4MB so if your PDF is potentially
    > > > larger you will either need to increase this limit or chunk out the PDF
    > > > contents.
    > > >
    > > > This is my stock function for doing this:-
    > > >
    > > > Sub SendFileToResponse(FilePath, FileName)
    > > >
    > > > Const clChunkSize = 1048576 ' 1MB
    > > >
    > > > Dim oStream, i
    > > > Response.Buffer = False
    > > >
    > > > Response.ContentType = "application/octet-stream"
    > > > Response.AddHeader "Content-Disposition", _
    > > > "Filename=" & FileName
    > > >
    > > > Set oStream = Server.CreateObject("ADODB.Stream")
    > > > oStream.Type = 1 ' Binary
    > > > oStream.Open
    > > > oStream.LoadFromFile FilePath
    > > >
    > > > For i = 1 To oStream.Size \ clChunkSize
    > > > Response.BinaryWrite oStream.Read(clChunkSize)
    > > > Next
    > > > If (oStream.Size Mod clChunkSize) <> 0 Then
    > > > Response.BinaryWrite oStream.Read(oStream.Size Mod clChunkSize)
    > > > End If
    > > > oStream.Close
    > > >
    > > > End Sub
    > > >
    > > > You would call this function as:-
    > > >
    > > > SendFileToResponse strFilePath, once
    > > >
    > > > since it chunks out the content there is no need to worry about buffer

    > size.
    > > > However before you can use it you will need to look at what is happening
    > > > earlier in your page that is already placing unwanted content in the
    > > > response.
    > > >
    > > > Anthony.
    > > >
    > > >
    > > > > --
    > > > > Betty
    > > >
    > > >
    > > >

    >
    >
    >
     
    c676228, Feb 9, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Merennulli
    Replies:
    1
    Views:
    413
    Merennulli
    Feb 22, 2006
  2. Mohammed Mazid
    Replies:
    2
    Views:
    1,954
    Jose Rubio
    Nov 29, 2003
  3. Dan Stromberg
    Replies:
    2
    Views:
    315
    Fredrik Lundh
    Oct 3, 2004
  4. Replies:
    10
    Views:
    639
  5. I.N. Galidakis
    Replies:
    8
    Views:
    850
    GTalbot
    Nov 16, 2008
Loading...

Share This Page