Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

open pdf in new window

Status
Not open for further replies.

LucasH

IS-IT--Management
Oct 28, 2003
93
US
HI all,

New to ASP.

I have a form that exports a crystal report to pdf and then displays the report in the browser:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dfdoCustomers As New _
CrystalDecisions.Shared.DiskFileDestinationOptions
Dim szFileName As String = "c:\windows\temp\myreport2.pdf"
dfdoCustomers.DiskFileName = szFileName
With bbreport
bbreport.SetParameterValue("Team", DropDownList1.SelectedItem.Value)
.ExportOptions.ExportDestinationType = _
CrystalDecisions.Shared.ExportDestinationType.DiskFile
.ExportOptions.ExportFormatType = _
CrystalDecisions.Shared.ExportFormatType.PortableDocFormat
.ExportOptions.DestinationOptions = dfdoCustomers
.Export()
End With
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Response.WriteFile(szFileName)
Response.Flush()
Response.Close()
End Sub

Pretty basic, however I have an issue and I am thinking it's not uncommon or hard, I just don't know how to solve it. I want the user to be able to go back to the original form (The form that the user clicked the button to export the report since it's based on parameters and I want the user to be able to re-submit using new parameters). However, after the pdf is opened, the back button is not available to return to the form. I am thinking of two solutions, 1) open the pdf in a new window, or 2) somehow make it possible to return to the original form. Any thoughts?
 
Personally, I'd open it in another window but that's just my preference...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Would you open it in Adobe or just another browser window (who cares?).

Any coding examples?
 
Well, I'd probably stream it to the client slightly differently and let the user decide what to do with it. I'll see if I can dig out an example as I've posted the function that I use in previous threads.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
LucasH, did you figure this out? I've has some trouble with this as well...
 
Yeah, what I did was when the user clicked the button to export the report, the report would export to a file on the server (I used seasionid.pdf), then redirected the client to a new window. In the new page's page_load, I had it simply open the pdf file and display it. Pretty basic really. I am surprised it took me that long to figure it out.
 
I open my pdf's in another window and pass a value to a session using response.redirect. then on the new window my pdf gets created based off the session value from the other form. this works very well with crystal.

 
Have you had any problems with exporting the crystal report to .pdf? It works great on my development server, but when I install the app on my production server it doesnt export anything. It appears to just not do anything!
Here is a snippet of code...I dont redirect to a different window with this, I simply open it in the current window and they use the back button. Sorry, the code is very lengthy, but didnt want to leave anythign out.

Dim OrderID As String

Dim oRpt As New ReportDocument
Dim strReportFileName As String
Dim crLogonInfo As CrystalDecisions.Shared.TableLogOnInfo

OrderID = Session.Item("OrderID")

strReportFileName = ConfigurationSettings.AppSettings("Report1") 'ProductionOrder.rpt
oRpt.Load(strReportFileName) '"C:\Inetpub\
crLogonInfo = oRpt.Database.Tables(0).LogOnInfo
crLogonInfo.ConnectionInfo.ServerName = ConfigurationSettings.AppSettings("SQLServer")
crLogonInfo.ConnectionInfo.UserID = ConfigurationSettings.AppSettings("SQLUser")
crLogonInfo.ConnectionInfo.Password = ConfigurationSettings.AppSettings("SQLPass")
crLogonInfo.ConnectionInfo.DatabaseName = ConfigurationSettings.AppSettings("SQLDatabase")
oRpt.Database.Tables(0).ApplyLogOnInfo(crLogonInfo)


''CR Variables
Dim crParameterFields As ParameterFields
Dim crParameterField As ParameterField

Dim crParameterValues As ParameterValues
Dim crParameterDiscreteValue As ParameterDiscreteValue

Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition

crParameterFieldDefinitions = oRpt.DataDefinition.ParameterFields

'this is the reference to the parameter
crParameterFieldDefinition = crParameterFieldDefinitions("vOrderID")
crParameterValues = crParameterFieldDefinition.CurrentValues

'Set the current values for the parameter field
crParameterDiscreteValue = New ParameterDiscreteValue
crParameterDiscreteValue.Value = OrderID
crParameterValues.Add(crParameterDiscreteValue)

crParameterDiscreteValue = Nothing

crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

Dim CrExportOptions As ExportOptions
Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions()
Dim CrFormatTypeOptions as New PdfRtfWordFormatOptions()

Dim strFile As String
strFile = "c:\" + OrderID + ".pdf"

'Set the destination path and file name
CrDiskFileDestinationOptions.DiskFileName = strFile


'Set export options
CrExportOptions = oRpt.ExportOptions

With CrExportOptions
'Set the destination to a disk file
.ExportDestinationType = ExportDestinationType.DiskFile
'Set the format to PDF
.ExportFormatType = ExportFormatType.PortableDocFormat
'Set the destination options to DiskFileDestinationOptions object
.DestinationOptions = CrDiskFileDestinationOptions
.FormatOptions = crFormatTypeOptions
End With

' Trap any errors that occur on export
'Try
'Export the report
oRpt.Export()
oRpt.Close()

' open an existing PDF form
Dim myFileInfo as FileInfo
Dim StartPos as Long = 0, FileSize as Long, EndPos as Long
Dim ContentType as String

ContentType = "application/pdf"

myFileInfo = New FileInfo(strFile)
FileSize = myFileInfo.Length
EndPos = FileSize

HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ClearHeaders()
HttpContext.Current.Response.ClearContent()

If Not (ContentType="") and (StartPos = 0) Then
HttpContext.Current.Response.ContentType = ContentType
End If
HttpContext.Current.Response.WriteFile(strFile, StartPos,EndPos)
HttpContext.Current.Response.End()
 
Thanks for your quick responses...

I use the redistributable because I have a full version of crystal reports. The report is called externally from the application, it is not an embedded resource. I dont have anything Visual Studio .Net on my production server...do I need it? It is not a development server.
 
Actually I should say I have Crystal Reports 9 .Net Server on my production server. I dont see any special way to deploy this for the redistributable version. Thanks.
 
<<<<I dont have anything Visual Studio .Net on my production server...do I need it? It is not a development server.

what????

are you not running IIS to run your asp.net app?

you need the frameworks installed on your server.



 
I just gave you directions on how to deploy CR. look at the instructions. it says for full version or the version .net comes with. you NEED to deploy it correctly onto your server in order for it to work.

 
Yes, I am running IIS, and have the frameworks installed. What I meant was that I dont have Visual Studio .Net installed to be able to go to Help - About to view which version of crystal i have. But i have confirmed that it is the full from Add/Remove programs.

So according to the doc you sent me it should work??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top