Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sending PDF to Browser
Message
General information
Forum:
ASP.NET
Category:
Other
Title:
Sending PDF to Browser
Miscellaneous
Thread ID:
01017212
Message ID:
01017212
Views:
57
I have an asp.net application that has a feature to allow a user to see a pdf. The system does not know whether or not the pdf exists - so it does a file.exists() then calls the function to send the pdf to the browser.

On my test server here, it works fine. I have put it on a production webserver, and I get a corrupted pdf. Here's the code that does it;
        Private Sub fi_exportfiletopdf(ByVal pcFile As String, ByVal pckey As String)
            ' this method will redirect the user to a pdf
            ' the system will prompt them to open the file or save it
            ' the pdf is opened in a separate window
            Response.Clear()
            Response.Buffer = True
            Response.ContentType = "application/pdf"
            Response.AddHeader("content-disposition", "attachment;filename=" + pckey + ".pdf")

            Response.Charset = ""
            Me.EnableViewState = False
            Dim oFileStream As FileStream
            Dim FileSize As Long

            oFileStream = New FileStream(pcFile, FileMode.Open)
            FileSize = oFileStream.Length

            Dim Buffer(CInt(FileSize)) As Byte
            oFileStream.Read(Buffer, 0, CInt(FileSize))
            oFileStream.Close()

            Response.OutputStream.Write(Buffer, 0, FileSize)
            Response.Flush()
            Response.Close()



        End Sub
I can actually browse to the file directly, and it works fine - somehow in the code, the pdf is being corrupted on this box. Any ideas?
Wayne Myers, MCSD
Senior Consultant
Forte' Incorporated
"The only things you can take to heaven are those which you give away" Author Unknown
Next
Reply
Map
View

Click here to load this message in the networking platform