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

Export not working

Status
Not open for further replies.

d0rthy

Programmer
Nov 21, 2001
8
0
0
GB
When i try to export a report in ASP I end up with a 0Kb sized file that is never released i.e. the Web Server holds onto it therefore making any operation on the file redundant. I am exporting to .rpt format. It is a dynamic report and works fine under other conditions. I have included the code here. All help would be greatly appreciated. All comments have been removed from the code to save space.

Thanks Mark


basePath = Request.ServerVariables("PATH_TRANSLATED")
While (Right(basePath, 1) <> &quot;\&quot; And Len(basePath) <> 0) '&quot;
iLen = Len(basePath) - 1
basePath = Left(basePath, iLen)
Wend

baseVirtualPath = Request.ServerVariables(&quot;PATH_INFO&quot;)
While (Right(baseVirtualPath, 1) <> &quot;/&quot; And Len(baseVirtualPath) <> 0)
iLen = Len(baseVirtualPath) - 1
baseVirtualPath = Left(baseVirtualPath, iLen)
Wend

If Not IsObject(session(&quot;oApp&quot;)) Then
Set session(&quot;oApp&quot;) = Server.CreateObject(&quot;CrystalRuntime.Application&quot;)
End If

ReportChosen = Request(&quot;ReportChosen&quot;)
ExportFile = Request(&quot;ExportFile&quot;)
If isObject(session(&quot;oRpt&quot;)) then
set session(&quot;oRpt&quot;) = nothing
End If
Set session(&quot;oRpt&quot;) = session(&quot;oApp&quot;).OpenReport(basePath & reportChosen, 1)
session(&quot;oRpt&quot;).DiscardSavedData
session(&quot;oRpt&quot;).MorePrintEngineErrorMessages = False
session(&quot;oRpt&quot;).EnableParameterPrompting = False

dbMachineName = Request (&quot;dbMachineName&quot;)
dbDatabaseName = Request (&quot;dbDatabaseName&quot;)
dbUserName = Request (&quot;dbUserName&quot;)
dbPassword = Request (&quot;dbPassword&quot;)

'Log on to tables
for each item in session(&quot;oRpt&quot;).Database.Tables
item.SetLogonInfo cstr(dbMachineName), cstr(dbDatabaseName), cstr(dbUserName), cstr(dbPassword)

if not item.TestConnectivity then
response.write &quot;ReCrystallize Warning: Unable to connect to data source using the following information.<BR><BR>&quot;
response.write &quot;Machine: &quot; & dbMachineName & &quot;<BR>&quot;
response.write &quot;Database: &quot; & dbDatabaseName & &quot;<BR>&quot;
response.write &quot;User Name: &quot; & dbUserName & &quot;<BR>&quot;
response.write &quot;Password: &quot; & dbPassword & &quot;<BR><BR><BR>&quot;
end if
next

set session(&quot;ParamCollection&quot;) = Session(&quot;oRpt&quot;).Parameterfields

'Set up parameters
for each item in session(&quot;ParamCollection&quot;)
'strip off leading and trailing &quot;{&quot;, &quot;?&quot; and &quot;}&quot; characters
'(a parameter called &quot;foo&quot; will be known as &quot;{?foo}&quot; by Crystal Reports
paramName = right ((left (item.name, len (item.name) - 1)), len(item.name)-3)

'Where the report uses a stored procedure, any stored procedure params will be known
'as &quot;{?@foo}&quot;. By convention we will have an associated HTML Form param called foo
if (left(paramName, 1) = &quot;@&quot;) then
paramName = right (paramName, len(paramName)-1)
end if

'response.write paramName
paramType = Request (paramName & &quot;type&quot;)
'response.write paramType

select case paramType
case &quot;number&quot;
paramValue = Request (paramName)
'response.write paramValue
Call item.SetCurrentValue (CDbl(paramValue), 7)
case &quot;string&quot;
paramValue = Request (paramName)
'response.write paramValue
Call item.SetCurrentValue (CStr(paramValue), 12)
case &quot;boolean&quot;
if UCase (Request (paramName)) = &quot;TRUE&quot; then
paramValue = True
else
paramValue = False
end if
'response.write paramValue
Call item.SetCurrentValue (CBool(paramValue), 9)
case &quot;currency&quot;
paramValue = Request (paramName)
'response.write paramValue
Call item.SetCurrentValue (CDbl(paramValue), 8)
case &quot;date&quot;
'tempd = CInt ( Request (paramName & &quot;Day&quot;))
'if tempd = 0 then
' tempd = 1
'end if
'tempm = CInt ( Request (paramName & &quot;Mon&quot;))
'if tempm = 0 then
' tempm = 1
'end if
'tempy = CInt ( Request (paramName & &quot;Year&quot;))
'paramValue = DateSerial ( CInt(tempy), CInt(tempm), CInt(tempd) )
'response.write paramValue
'Call item.SetCurrentValue (CDate(paramValue), 10)
'
' Extract day/month/year and built a string representation of that date in
' a suitable format (&quot;yyyy-mm-dd&quot;)
'
tempd = ( Request (paramName & &quot;Day&quot;))
tempm = ( Request (paramName & &quot;Mon&quot;))
tempy = ( Request (paramName & &quot;Year&quot;))
tempdatestring = tempy & &quot;-&quot; & tempm & &quot;-&quot; & tempd
'response.write ( &quot; &quot; & tempdatestring &&quot;<BR>&quot; )
Call item.SetCurrentValue (CStr(tempdatestring), 12)
end select
next


On Error Resume Next


session(&quot;oRpt&quot;).ReadRecords
If Err.Number <> 0 Then
Response.Write &quot;An Error (&quot; & Err.Number & &quot;:&quot; & Err.Description & &quot;) has occured on the server in attempting to access the data source&quot;
Else

If IsObject(session(&quot;oPageEngine&quot;)) Then
set session(&quot;oPageEngine&quot;) = nothing
End If
set session(&quot;oPageEngine&quot;) = session(&quot;oRpt&quot;).PageEngine
End If

%>

<%
On Error Resume Next


set CrystalExportOptions = Session(&quot;oRpt&quot;).ExportOptions

CrystalExportOptions.DiskFileName = ExportFile
CrystalExportOptions.FormatType = 1
CrystalExportOptions.DestinationType = 1

Session(&quot;oRpt&quot;).Export False

If Err.Number = 0 Then
' Response.Write &quot;Export successful&quot;
Else
' Response.Write &quot;Export failed&quot;
End %>
 
Can noone help me on this one - it is still bothering me!!
 
See if this documentation helps you out at all:

Exporting a report generates a 0-Byte file.

The information in the article refers to:
Report Designer Component 8


Applies to:

Reported version only
0 Byte file when exporting through the Export dialog box
Export ActiveX Designer reports (DSR)



Synopsis

An application using an ActiveX designer report (.DSR), which is created using the Report Designer Component (RDC), is exported at runtime.

When the report is exported through the 'Export' dialog box, the exported file contains no information and has no physical size (0-bytes).


Solution

This issue has been tracked. Track ID 37694.

There are two scenarios in which this issue can occur.

The first scenario is with Crystal Reports version 7 Maintenance Release 1 on a Microsoft Windows NT 4 machine. In this scenario, the first time the report is exported a complete file is generated. The second time the report is exported, to the same format, a 0-byte file is generated.

The second scenario is with Crystal Reports version 8 Developers Edition on a Microsoft Windows NT4 or Microsoft Windows 2000 platform. In this scenario, the first time a report is exported, a 0-byte file is generated.

There are two possible workarounds for this issue:
- Export the DSR through code.
- Save the DSR as a Crystal Report file (RPT) and export the RPT using the Export dialog box.

Export the DSR through code===================================

Sample Code:

The following sample code will:
- Set the Export options
- Export the Crystal Report file to a word document

'Create a new instance of the DSR
Dim Report As New CrystalReport1

Private Sub Form_Load()
'Export to disk
Report.ExportOptions.DestinationType = crEDTDiskFile
'Export to Microsoft Word format
Report.ExportOptions.FormatType = crEFTWordForWindows
'Export path and file name
Report.ExportOptions.DiskFileName = &quot;c:\MyReport.doc&quot;
'Export without displaying the 'Export' dialog box
Report.Export False
End Sub


=========================================================

Save the DSR to an RPT and export the RPT=========================

The following sample code will:
- Save the DSR as a RPT
- Display the 'Export' dialog box.
- Delete the RPT

'Declare a report object for the Crystal Report file
Dim crxReport As CRAXDRT.Report
'Create a new instance of the DSR
Dim Report As New CrystalReport1
'Create a new instance of the application object
Dim crxApplication As New CRAXDRT.Application

Private Sub Form_Load()
'Save the DSR as a Crystal Report file in a version 8 format
Report.SaveAs &quot;c:\TestExport.rpt&quot;, cr80FileFormat

'Open the report
Set crxReport = crxApplication.OpenReport(&quot;c:\TestExport.rpt&quot;, 1)

'Add any code needed to run the report.
'For example connecting using SetLogOnInfo, setting Parameters, and so on

'Display the 'Export' dialog box
crxReport.Export True

'Delete the report file
Kill &quot;c:\TestExport.rpt&quot;
End Sub
=========================================================

 
thanks Lorraine,

but it tried this. it doesn't seem to work. i call the export functionality in another file and i have created this file from it. However, this file just does not want to work. strange problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top