Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Export not working

Export not working

Export not working

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) <> "\" And Len(basePath) <> 0) '"
    iLen = Len(basePath) - 1
    basePath = Left(basePath, iLen)

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

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

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

dbMachineName    = Request ("dbMachineName")
dbDatabaseName    = Request ("dbDatabaseName")
dbUserName    = Request ("dbUserName")
dbPassword    = Request ("dbPassword")

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

    if not item.TestConnectivity then
        response.write "ReCrystallize Warning:  Unable to connect to data source using the following information.<BR><BR>"
        response.write "Machine: " & dbMachineName & "<BR>"
        response.write "Database: " & dbDatabaseName & "<BR>"
        response.write "User Name: " & dbUserName & "<BR>"
        response.write "Password: " & dbPassword & "<BR><BR><BR>"    
    end if
set session("ParamCollection") = Session("oRpt").Parameterfields

'Set up parameters
for each item in session("ParamCollection")
    'strip off leading and trailing "{", "?" and "}" characters
    '(a parameter called "foo" will be known as "{?foo}" 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 "{?@foo}". By convention we will have an associated HTML Form param called foo
    if (left(paramName, 1) = "@") then
        paramName    = right (paramName, len(paramName)-1)
    end if

    'response.write paramName
    paramType    = Request (paramName & "type")
    'response.write paramType
    select case paramType
    case "number"
        paramValue    = Request (paramName)
        'response.write paramValue
        Call item.SetCurrentValue (CDbl(paramValue), 7)    
    case "string"
        paramValue    = Request (paramName)
        'response.write paramValue
        Call item.SetCurrentValue (CStr(paramValue), 12)
    case "boolean"
        if UCase (Request (paramName)) = "TRUE" then
            paramValue    = True
            paramValue    = False    
        end if   
        'response.write paramValue
        Call item.SetCurrentValue (CBool(paramValue), 9)
    case "currency"
        paramValue    = Request (paramName)
        'response.write paramValue
        Call item.SetCurrentValue (CDbl(paramValue), 8)
    case "date"
        'tempd = CInt ( Request (paramName & "Day"))
        'if tempd = 0 then
        '    tempd = 1
        'end if    
        'tempm = CInt ( Request (paramName & "Mon"))
        'if tempm = 0 then
        '    tempm = 1
        'end if    
        'tempy = CInt ( Request (paramName & "Year"))
        '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 ("yyyy-mm-dd")
        tempd = ( Request (paramName & "Day"))
        tempm = ( Request (paramName & "Mon"))
        tempy = ( Request (paramName & "Year"))
        tempdatestring = tempy & "-" & tempm & "-" & tempd
        'response.write ( " " & tempdatestring &"<BR>" )
        Call item.SetCurrentValue (CStr(tempdatestring), 12)
    end select

On Error Resume Next       

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

  If IsObject(session("oPageEngine")) Then                              
      set session("oPageEngine") = nothing
  End If
set session("oPageEngine") = session("oRpt").PageEngine
End If                                                                


On Error Resume Next                                                  

set CrystalExportOptions = Session("oRpt").ExportOptions

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

Session("oRpt").Export False

If Err.Number = 0 Then   
'  Response.Write "Export successful"
'  Response.Write "Export failed"
End %>

RE: Export not working

Can noone help me on this one - it is still bothering me!!

RE: Export not working

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)



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).


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 = "c:\MyReport.doc"
'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 "c:\TestExport.rpt", cr80FileFormat

'Open the report
Set crxReport = crxApplication.OpenReport("c:\TestExport.rpt", 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 "c:\TestExport.rpt"
End Sub

RE: Export not working

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close