Solved

Save PDF from asp and get asp code ?

Posted on 2010-11-11
6
236 Views
Last Modified: 2012-05-10
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
Comment
Question by:Thunder724
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 3

Expert Comment

by:mortimer452
ID: 34117274
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
 
LVL 4

Author Comment

by:Thunder724
ID: 34117315
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
 
LVL 3

Accepted Solution

by:
mortimer452 earned 500 total points
ID: 34118167
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!

 
LVL 4

Author Comment

by:Thunder724
ID: 34119781
I'm getting the following error when I either open or save the file and open in adobe?
0
 
LVL 4

Author Comment

by:Thunder724
ID: 34119786
Sorry, here it is again.. error message
0
 
LVL 4

Author Comment

by:Thunder724
ID: 34121791
Hey I got it working thanks :)
0

Featured Post

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to create an MVC5, Razor Widget 2 50
Access-Control-Allow-Origin 4 42
How do I "share" on social sites? 2 38
Manage big list of parameter list 8 20
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question