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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export with ASP to pdf / excel / printer

Status
Not open for further replies.

rhysmeister

Programmer
May 29, 2003
54
GB
I am trying to export a report with ASP to various formats but cannot seem to get it right.

Code:
<%
'========================================
'// Get variables from the post and setup
'// variables for use.
'========================================

Dim startYear
Dim startMonth
Dim startDay
Dim endYear
Dim endMonth
Dim endDay

startYear = Request.QueryString("startYear")
startMonth = Request.QueryString("startMonth")
startDay = Request.QueryString("startDay")
endYear = Request.QueryString("endYear")
endMonth = Request.QueryString("endMonth")
endDay = Request.QueryString("endDay")

Dim Account
Dim BookingNumber
Dim Tariff
Dim BookedBy
Dim BookingMethod
Dim PickUpCompanyName
Dim DropCompany
Dim PickUpTown
Dim PickUpPostCode
Dim DropPostCode
Dim Ref1
Dim Ref2
Dim Ref3

Account = Request.QueryString("Account")
BookingNumber = Request.QueryString("BookingNumber")
Tariff = Request.QueryString("Tariff")
BookedBy = Request.QueryString("BookedBy")
BookingMethod = Request.QueryString("BookingMethod")
PickUpCompanyName = Request.QueryString("PickUpCompanyName")
DropCompany = Request.QueryString("DropCompany")
PickUpTown = Request.QueryString("PickUpTown")
PickUpPostCode = Request.QueryString("PickUpPostCode")
DropPostCode = Request.QueryString("DropPostCode")
Ref1 = Request.QueryString("Ref1")
Ref2 = Request.QueryString("Ref2")
Ref3 = Request.QueryString("Ref3")

If Account = NULL Then
	Reponse.Write("Massive error you are doomed!")
End If

'============================================
'// SPECIFY THE FULL REPORT PATH AND FILENAME
'============================================

	ReportName = "C:\webreports\UsageReport Export to PDF.rpt"
%>
<%
'=============================================================
'// ASP INCLUDE FILE CODE THAT IS ALWAYS REQUIRED
'// REFERENCES TO REPORTPATH HAVE BEEN EDITED OUT OF THIS FILE
'=============================================================
%>
<!-- #include file="AlwaysRequiredSteps.asp" -->
<%
'==========================================================================
'// ENABLE PARENT PATHS IN IIS. DB LOGON INFO NOT TO BE PLACED IN WEB SHARE
'==========================================================================
%>
<!-- #include file="..\..\..\..\..\..\..\webreports\crystalweblogon.asp" -->
<%
'===============================================================
'// SETUP REPORT PARAMETER INDEX. NO NEED TO ALTER THIS FUNCTION
'===============================================================
%>
	<%
Public Sub PassParameter(param_index, param_value)
    Dim paramValue		' discrete parameter value
    Dim param_old		' parameter field in the report
    Dim param_new		'parameter field that will replace old parameter

    ' Create a discrete parameter field value
    Set paramValue = objFactory.CreateObject("CrystalReports.ParameterFieldDiscreteValue")

    ' Set parameter field value to the new parameter value
    paramValue.Value = param_value

    ' Get parameter in the report at the position param_index
    Set param_old = clientDoc.DataDefinition.ParameterFields.Item(param_index)

    ' Create a new parameter field object
    Set param_new = objFactory.CreateObject("CrystalReports.ParameterField")

    ' Copy properties of old parameter to new parameter
    param_old.CopyTo param_new

    ' Add discrete value to this new parameter field
    param_new.CurrentValues.Add paramValue
	
    ' Modify parameter through the DataDefControler and the ParameterFieldController
    clientDoc.DataDefController.ParameterFieldController.Modify param_old, param_new

    ' Clean up
    Set paramValue = Nothing
    Set param_new = Nothing
 End Sub
 
'===========================================
'// NOW ASSIGN VALUES TO PARAMETERS BY INDEX
'===========================================
%>
<%

PassParameter 0, DateSerial(startYear, startMonth, startDay) & " " & TimeSerial(0,0,0)
PassParameter 1, DateSerial(endYear, endMonth, endDay) & " " & TimeSerial(23,59,59)
PassParameter 2, Account
PassParameter 3, BookingNumber
PassParameter 4, Tariff
PassParameter 5, BookedBy
PassParameter 6, BookingMethod
PassParameter 7, PickUpCompanyName
PassParameter 8, DropCompany
PassParameter 9, PickUpTown
PassParameter 10, DropTown
PassParameter 11, PickUpPostCode
PassParameter 12, DropPostCode

PassParameter 13, Ref1
PassParameter 14, Ref2
PassParameter 15, Ref3
'================================
'// ALL SETUP, NOW RUN THE REPORT
'================================
%>
<%
'==================================================================
' WORKING WITH PRINT OUTPUT CONTROLLER
'   - Retreive the bytearray from the PrintOutputController
'   - Setup the Response object to stream the file
'   - Cleat the Response object
'   - Add a custom header for an inline file type with a default file name
'   - Set the Content Type to application/pdf
'   - Send the bytearray to the browser through the Response object, used
'     detachArray method for quicker tranfer of data
'==================================================================




Dim byteArray, bufArray

' Constants
crReportExportFormatPDF = 5

' Retreive the bytearray from the PrintOutputController
Set byteArray = clientDoc.PrintOutputController.Export(crReportExportFormatPDF)

' Setup the Response object attributes

' Clear the Response object
'Response.Clear
' Add a custom header for an inline file type with a default file name
Response.AddHeader "content-disposition", "inline;filename=untitled.pdf"
' Set the Content Type to application/pdf
Response.ContentType = "application/pdf"

' Send the bytearray to the browser through the Response object, used
' detachArray method for quicker tranfer of data
Response.BinaryWrite byteArray.detachArray
%>

I have used this code to run the report in the Report Viewer with no problems but I can't get it to export. Any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top