Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Save PDF from asp and get asp code ?

Posted on 2010-11-11
6
Medium Priority
?
239 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 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

636 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