• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 241
  • Last Modified:

Save PDF from asp and get asp code ?

Hi all,
I have an app that simply shows a PDF file.
When pressing the "save" icon it defualts to "default" as the file name and saves it as pure asp code (jibberish).  If I change the name of the file to anything it saves as a proper PDF file.
What am I doing wrong?
0
Thunder724
Asked:
Thunder724
  • 4
  • 2
1 Solution
 
mortimer452Commented:
How are you displaying the PDF file?

Sounds like you aren't setting the Content-Type and Content-Disposition headers correctly.  Should be something like this:

Response.ClearHeaders()
Response.AddHeader("Content-Type","Application/octet-stream")
Response.AddHeader("Content-Disposition","attachment; filename=MyFile.pdf")
0
 
Thunder724Author Commented:
thanks mortimer...
i'm an acomplished client server developer; but web dev is very new to me.  I try to code pure vb.net and and confused to the asp page code part of everything... below is my vb code..

    Public Sub ViewFile(ByVal FName$)
        Dim path As String = FName$
        Dim file As New System.IO.FileInfo(path)

        If file.Exists Then
            Response.Clear()

            Select Case UCase(file.Extension)
                Case ".PDF"
                    Response.ContentType = "Application/pdf"
                Case ".DOC", ".DOCX"
                    Response.ContentType = "Application/msword"
            End Select

            Response.WriteFile(file.FullName)
            Response.End()

        End If
    End Sub

    Protected Sub btnPatronInfo_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnPatronInfo.Click
        Dim OpenFile$ = Server.MapPath(".") & "\Forms\BnaiPatronInfoWeb1.pdf"
        ViewFile(OpenFile$)
    End Sub

    Protected Sub btnAuctionitems0_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnOrderTickets.Click
        Dim OpenFile$ = Server.MapPath(".") & "\Forms\Auction2010TicketFormWeb1.pdf"
        ViewFile(OpenFile$)
    End Sub

    Protected Sub btnViewInventation_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnViewInventation.Click
        Dim OpenFile$ = Server.MapPath(".") & "\Forms\Auction2010InviteWeb2.pdf"
        ViewFile(OpenFile$)
    End Sub
0
 
mortimer452Commented:
Yeah your problem is that even though you're telling the browser the content-type is a PDF, the page name is still .aspx so teh end-user has to rename it after saving

Use the code I specified above, specifying "application/octet-stream" as the content-type.  This tells the browser it's just generic binary data

The content-dispostion of "attachment; filename=MyFile.pdf" forces the browser to prompt with the Open/Save dialog allowing the user to either view the file in their browser or save it to disk, and provides a filename.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Thunder724Author Commented:
I'm getting the following error when I either open or save the file and open in adobe?
0
 
Thunder724Author Commented:
Sorry, here it is again.. error message
0
 
Thunder724Author Commented:
Hey I got it working thanks :)
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now