Google 网上论坛不再支持新的 Usenet 帖子或订阅项。历史内容仍可供查看。

Help! Crystal Reports and ASP/pdf export

已查看 171 次
跳至第一个未读帖子

Brenda Mota

未读,
2001年4月17日 16:12:442001/4/17
收件人
Hi there.

I've searched high and low, and I can't seem to find the answer to my
question anywhere. I'm looking for help from someone who is familiar with
Crystal Reports and Active Server pages. I'm trying to create a report and
export it in .pdf format. Here's the scenario:

1. Client enters information in html form, info is added to Access database
and record is assigned an ID number (autonumber - 1, 2, 3,... 1004, etc.)
2. Client is redirected to confirmation page, which shows this
system-generated ID number.
3. Client enters this ID number in a text box, hits submit and...
(this is where the trouble starts)
4. ID number is passed to a selection formula, the report is run
automatically, and is then exported to .pdf format.
5. Client is redirected to page with link to .pdf format report.

I have the samples from Crystal Reports 8.5 which show the code for the
selection formula and the .pdf export in separate reports. I've tried
running both of them, and they both work. It should be simple to "combine"
the two and make it work, right? WRONG!! Here is the code I've come up
with. If you need the original code from the 2 samples, email me and I'll
copy them to you.

The error I'm getting is: Error Occurred Reading Records: File not found.

Thanks in advance.
Brenda

<%@ LANGUAGE="VBSCRIPT" %>

<%

' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

' Applying a Record Selection Formula to a Report

' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =


'

' CONCEPT:

'

' This application is designed to demonstrate how to define a

' record selection formula at runtime. For this example the

' selection formula is "constructed" from information from

' the calling HTML page. However all you need to do to pass

' a valid Crystal Reports Selection Formula as a string.

'===========================================================================
========

'Create the Crystal Reports Objects

'===========================================================================
========

'

'You will notice that the Crystal Reports objects are scoped as session
variables.

'This is because the page on demand processing is performed by a prewritten

'ASP page called "rptserver.asp". In order to allow rptserver.asp easy
access

'to the Crystal Report objects, we scope them as session variables. That way

'any ASP page running in this session, including rptserver.asp, can use
them.

reportname = "competentabletopay.rpt"

'This line creates a string variable called reportname that we will use to
pass

'the Crystal Report filename (.rpt file) to the OpenReport method.

'To re-use this code for your application you would change the name of the
report

'so as to reference your report file.

' CREATE THE APPLICATION OBJECT

If Not IsObject (session("oApp")) Then

Set session("oApp") = Server.CreateObject("CrystalRuntime.Application")

End If

'This "if/end if" structure is used to create the Crystal Reports
Application

'object only once per session. Creating the application object -
session("oApp")

'loads the Crystal Report Design Component automation server (craxdrt.dll)
into memory.

'

'We create it as a session variable in order to use it for the duration of
the

'ASP session. This is to elimainate the overhead of loading and unloading
the

'craxdrt.dll in and out of memory. Once the application object is created in

'memory for this session, you can run many reports without having to
recreate it.


' CREATE THE REPORT OBJECT

'

'The Report object is created by calling the Application object's OpenReport
method.

Path = Request.ServerVariables("PATH_TRANSLATED")

While (Right(Path, 1) <> "\" And Len(Path) <> 0)

iLen = Len(Path) - 1

Path = Left(Path, iLen)

Wend


'This "While/Wend" loop is used to determine the physical path (eg: C:\) to
the

'Crystal Report file by translating the URL virtual path (eg:
http://Domain/Dir)

'OPEN THE REPORT (but destroy any previous one first)

If IsObject(session("oRpt")) then

Set session("oRpt") = nothing

End if

On error resume next

Set session("oRpt") = session("oApp").OpenReport(path & reportname, 1)

'This line uses the "PATH" and "reportname" variables to reference the
Crystal

'Report file, and open it up for processing.

If Err.Number <> 0 Then

Response.Write "Error Occurred creating Report Object: " & Err.Description

Set Session("oRpt") = nothing

Set Session("oApp") = nothing

Session.Abandon

Response.End

End If

'This On error resume next block checks for any errors on creating the
report object

'we are specifically trapping for an error if we try to surpass the maximum
concurrent

'users defined by the license agreement. By destroying the application and
report objects

'on failure we ensure that this client session will be able to run reports
when a license is free

'

'Notice that we do not create the report object only once. This is because

'within an ASP session, you may want to process more than one report. The

'rptserver.asp component will only process a report object named
session("oRpt").

'Therefor, if you wish to process more than one report in an ASP session,
you

'must open that report by creating a new session("oRpt") object.

session("oRpt").MorePrintEngineErrorMessages = False

session("oRpt").EnableParameterPrompting = False

'These lines disable the Error reporting mechanism included the built into
the

'Crystal Report Design Component automation server (craxdrt.dll).

'This is done for two reasons:

'1. The print engine is executed on the Web Server, so any error messages

' will be displayed there. If an error is reported on the web server, the

' print engine will stop processing and you application will "hang".

'

'2. This ASP page and rptserver.asp have some error handling logic desinged

' to trap any non-fatal errors (such as failed database connectivity) and

' display them to the client browser.

'

'**IMPORTANT** Even though we disable the extended error messaging of the
engine

'fatal errors can cause an error dialog to be displayed on the Web Server
machine.

'For this reason we reccomend that you set the "Allow Service to Interact
with Desktop"

'option on the "World Wide Web Publishing" service (IIS service). That way
if your ASP

'application freezes you will be able to view the error dialog (if one is
displayed).

'===========================================================================
===========

'Defining the Selection Formula

'===========================================================================
===========

'This information is taken from the form which calls this code. There is
one visible text box, called "ID", and

'two hidden text boxes, which hold the field name ("ID") and the operator
symbol (=)

field = Request.Form("field")

value = Request.Form("ID")

operator_symbol = Request.Form("operator_symbol")

selection_formula = cstr(field) & cstr(operator_symbol) & " " & cstr(value)

session("oRpt").DiscardSavedData

session("oRpt").RecordSelectionFormula = cstr(selection_formula)

'This then means session("oRpt").RecordSelectionFormula = cstr(ID = ID
number (say, 4))

'

'===========================================================================
=========

' Retrieve the Records and Create the "Page on Demand" Engine Object

'===========================================================================
=========

On Error Resume Next

session("oRpt").ReadRecords

If Err.Number <> 0 Then

Response.Write "Error Occurred Reading Records: " & Err.Description

Set Session("oRpt") = nothing

Set Session("oApp") = nothing

Session.Abandon

Response.End

Else

If IsObject(session("oPageEngine")) Then

set session("oPageEngine") = nothing

End If

set session("oPageEngine") = session("oRpt").PageEngine

End If

'===========================================================================
=========

' Exporting the Crystal Report

'===========================================================================
=========

Path = Request.ServerVariables("PATH_TRANSLATED")

While (Right(Path, 1) <> "\" And Len(Path) <> 0)

iLen = Len(Path) - 1

Path = Left(Path, iLen)

Wend

session("filename") = Request.Form("ID") + ".pdf"

ExportType = 31

'These lines collect the values passed from the calling HTML page for the
export

'type and filename

Set session("ExportOptions") = Session("oRpt").ExportOptions

'First we create an export options collection which allows us access

'to the exporting properties of the automation server.

session("ExportFileName") = Path + "\exports\" + cstr(session("filename"))

session("ExportOptions").FormatType = cint(ExportType)

'This line sets the file type that the report will be exported to. We

'use the value that we collected from the calling HTML page.

session("ExportOptions").DestinationType = 1

'This line sets the destination of the exported file. 1 means that

'we are writing the file to disk.

On Error Resume Next

Session("oRpt").Export False

If Err.Number <> 0 Then

Response.Write "Error Occurred Exporting Report: " & Err.Description &
Err.number

Set Session("oRpt") = nothing

Set Session("oApp") = nothing

Session.Abandon

Response.End

Else

If IsObject(session("oPageEngine")) Then

set session("oPageEngine") = nothing

End If

set session("oPageEngine") = session("oRpt").PageEngine

End If

session("ExportVirtualDirectory") = "http://proceratops/aspreports/exports/"

'The ExportVirtualDirectory variable is used to reference the a web
directory

'so that we can point the browser to the newly exported file.

'===========================================================================
=========

' Point the browser to an HTML page that will

' provide a hyperlink to the newly exported file

'===========================================================================
=========

'Response.Redirect("exported.asp")

%>

Jeff Dillon

未读,
2001年4月17日 16:30:472001/4/17
收件人
Does the report run OK if you just run it locally, within CR?

Jeff

"Brenda Mota" <mot...@hotmail.com> wrote in message
news:e0xwlp3xAHA.2208@tkmsftngp02...

Brenda Mota

未读,
2001年4月18日 09:53:082001/4/18
收件人
Thank you for asking that. I had just gotten a new computer at work, and
the file was pointing to the old database location. I thought the error was
different from the first one I'd received last week.

The error I'm receiving now is:
Error Occurred Exporting Report: Invalid directory.

I've checked, and the directory is where it should be. Any ideas?

Oh, yes. The report does run properly in CR. If I substitute the report
for the ones in the samples I mentioned in the first post, it runs properly
as well. I think it's the asp code calling the report and "filling in the
blanks" that's wrong.

Any help you could provide would be greatly appreciated.

Thanks.
Brenda


"Jeff Dillon" <jef...@fidalgo.net> wrote in message
news:uxAR113xAHA.1936@tkmsftngp04...

0 个新帖子