Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP.net pdf file opening in debug mode but not on web

Posted on 2016-11-05
13
Medium Priority
?
52 Views
Last Modified: 2016-11-07
Hi
I use the following VB.net code in my ASP.net web app to view a pdf file. It works in debug mode but not in the deployed site online

  Protected Sub btnView_Click(sender As Object, e As EventArgs) Handles btnView.Click
        Try
            Dim oSelectedFile As String
            If Me.ListBox1.SelectedItem.Text <> "" Then
                oSelectedFile = Me.ListBox1.SelectedItem.Text
            Else
                Exit Sub
            End If
            Response.Clear()
            'Dim filePath As String = "~/Uploads/GREAT.pdf"
            Dim filePath As String = "~/Uploads/" & oSelectedFile
            Response.ContentType = "application/pdf"
            Response.WriteFile(filePath)
        Catch ex As Exception
            'Response.Write(ex.Message)
            Me.lblErrorDeleting.Text = ex.Message & " hr556"
        End Try
    End Sub
0
Comment
Question by:Murray Brown
[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
  • 7
  • 6
13 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 41875304
>>It works in debug mode

and in release mode it does what ?  (Before jumping to conclusions that the version you use on the web site is working but the problem is with the web site you should test it first.)
0
 

Author Comment

by:Murray Brown
ID: 41876723
In debug mode it opens the pfd
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 41876733
To repeat myself (because debug and release builds of code are not the same, and because you distribute a release build not a debug build):
and in release mode it does what ?
0
AWS Certified Solutions Architect - Associate

This course has been developed to provide you with the requisite knowledge to not only pass the AWS CSA certification exam but also gain the hands-on experience required to become a qualified AWS Solutions architect working in a real-world environment.

 

Author Comment

by:Murray Brown
ID: 41876742
This is ASP.net of course so by release mode if you mean deployed to the web then this mode doesn't work. Nothing happens
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 41876762
Please confirm you have the web config set to use the release mode (debug=false) otherwise you have a set of code that works and a different set of code running in a browser somewhere else which fails.  I'm just trying to rule out one possible source of the error.
0
 

Author Comment

by:Murray Brown
ID: 41876767
Here's the markup in web config. Should debug=false here?

  <system.web>
    <httpHandlers>
      <add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        validate="false" />
    </httpHandlers>
    <authentication mode="None"/>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.5.2">
      <assemblies>
        <add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </assemblies>
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 41876778
Set the debug to false.  (It should result in faster code because all the debugging is removed at compile time).  
In reality I'm expecting it to still fail BUT it might be the problem.


ps.
http://aspalliance.com/1341_The_Infamous_DebugTrue_Attribute_in_ASPNET
0
 

Author Comment

by:Murray Brown
ID: 41876919
Hi. Thanks but unfortunately that didn't help
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 41876964
OK, that clears one potential problem out of the way.
Am I correct that you don't see any error message in the label?


Does this show what you expect in the (error) label in terms of the path, or nothing at all (which implies the click event isn't getting processed).

 Protected Sub btnView_Click(sender As Object, e As EventArgs) Handles btnView.Click
        Try
            Dim oSelectedFile As String
            If Me.ListBox1.SelectedItem.Text <> "" Then
                oSelectedFile = Me.ListBox1.SelectedItem.Text
            Else
                Exit Sub
            End If
            Response.Clear()
            'Dim filePath As String = "~/Uploads/GREAT.pdf"
            Dim filePath As String = "~/Uploads/" & oSelectedFile
Me.lblErrorDeleting.Text = filePath
            Response.ContentType = "application/pdf"
            Response.WriteFile(filePath)
        Catch ex As Exception
            'Response.Write(ex.Message)
            Me.lblErrorDeleting.Text = ex.Message & " hr556"
        End Try
    End Sub
0
 

Author Comment

by:Murray Brown
ID: 41877067
It shows nothing at all
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 2000 total points
ID: 41877156
So the button click event isn't being called in that case.  Do other button click events work?
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 41877161
Or paranoia - just in case
Protected Sub btnView_Click(sender As Object, e As EventArgs) Handles btnView.Click
        Try
            Dim oSelectedFile As String
            If Me.ListBox1.SelectedItem.Text <> "" Then
                oSelectedFile = Me.ListBox1.SelectedItem.Text
            Else
Me.lblErrorDeleting.Text = "Nothing selected"
                Exit Sub
0
 

Author Closing Comment

by:Murray Brown
ID: 41877475
Hi. Thanks very much for the direction. It turns out that one of the pdf files was causing the problem where the button click wasn't firing. I'm not sure how this works but your help got me there. Much appreciated!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

722 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