Murray Brown
asked on
ASP.net pdf file opening in debug mode but not on web
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.T ext <> "" Then
oSelectedFile = Me.ListBox1.SelectedItem.T ext
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(filePat h)
Catch ex As Exception
'Response.Write(ex.Message )
Me.lblErrorDeleting.Text = ex.Message & " hr556"
End Try
End Sub
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.T
oSelectedFile = Me.ListBox1.SelectedItem.T
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(filePat
Catch ex As Exception
'Response.Write(ex.Message
Me.lblErrorDeleting.Text = ex.Message & " hr556"
End Try
End Sub
ASKER
In debug mode it opens the pfd
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 ?
and in release mode it does what ?
ASKER
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
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.
ASKER
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.DataVi sualizatio n.Charting .ChartHttp Handler, System.Web.DataVisualizati on, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad3 64e35"
validate="false" />
</httpHandlers>
<authentication mode="None"/>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.5.2">
<assemblies>
<add assembly="System.Web.DataV isualizati on, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD3 64E35"/>
</assemblies>
<system.web>
<httpHandlers>
<add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVi
validate="false" />
</httpHandlers>
<authentication mode="None"/>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.5.2">
<assemblies>
<add assembly="System.Web.DataV
</assemblies>
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
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
ASKER
Hi. Thanks but unfortunately that didn't help
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.T ext <> "" Then
oSelectedFile = Me.ListBox1.SelectedItem.T ext
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(filePat h)
Catch ex As Exception
'Response.Write(ex.Message )
Me.lblErrorDeleting.Text = ex.Message & " hr556"
End Try
End Sub
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.T
oSelectedFile = Me.ListBox1.SelectedItem.T
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(filePat
Catch ex As Exception
'Response.Write(ex.Message
Me.lblErrorDeleting.Text = ex.Message & " hr556"
End Try
End Sub
ASKER
It shows nothing at all
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.T ext <> "" Then
oSelectedFile = Me.ListBox1.SelectedItem.T ext
Else
Me.lblErrorDeleting.Text = "Nothing selected"
Exit Sub
Protected Sub btnView_Click(sender As Object, e As EventArgs) Handles btnView.Click
Try
Dim oSelectedFile As String
If Me.ListBox1.SelectedItem.T
oSelectedFile = Me.ListBox1.SelectedItem.T
Else
Me.lblErrorDeleting.Text = "Nothing selected"
Exit Sub
ASKER
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!
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.)