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)
Wend
baseVirtualPath = Request.ServerVariables("PATH_INFO"
While (Right(baseVirtualPath, 1) <> "/" And Len(baseVirtualPath) <> 0)
iLen = Len(baseVirtualPath) - 1
baseVirtualPath = Left(baseVirtualPath, iLen)
Wend
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"
.DiscardSavedData
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
next
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
else
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
next
On Error Resume Next
session("oRpt"
.ReadRecords
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"
Else
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"
Else
' Response.Write "Export failed"
End %>
Thanks Mark
basePath = Request.ServerVariables("PATH_TRANSLATED"
While (Right(basePath, 1) <> "\" And Len(basePath) <> 0) '"
iLen = Len(basePath) - 1
basePath = Left(basePath, iLen)
Wend
baseVirtualPath = Request.ServerVariables("PATH_INFO"
While (Right(baseVirtualPath, 1) <> "/" And Len(baseVirtualPath) <> 0)
iLen = Len(baseVirtualPath) - 1
baseVirtualPath = Left(baseVirtualPath, iLen)
Wend
If Not IsObject(session("oApp"
Set session("oApp"
End If
ReportChosen = Request("ReportChosen"
ExportFile = Request("ExportFile"
If isObject(session("oRpt"
set session("oRpt"
End If
Set session("oRpt"
session("oRpt"
session("oRpt"
session("oRpt"
dbMachineName = Request ("dbMachineName"
dbDatabaseName = Request ("dbDatabaseName"
dbUserName = Request ("dbUserName"
dbPassword = Request ("dbPassword"
'Log on to tables
for each item in session("oRpt"
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
next
set session("ParamCollection"
'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) = "@"
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
else
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
next
On Error Resume Next
session("oRpt"
If Err.Number <> 0 Then
Response.Write "An Error (" & Err.Number & ":" & Err.Description & "
Else
If IsObject(session("oPageEngine"
set session("oPageEngine"
End If
set session("oPageEngine"
End If
%>
<%
On Error Resume Next
set CrystalExportOptions = Session("oRpt"
CrystalExportOptions.DiskFileName = ExportFile
CrystalExportOptions.FormatType = 1
CrystalExportOptions.DestinationType = 1
Session("oRpt"
If Err.Number = 0 Then
' Response.Write "Export successful"
Else
' Response.Write "Export failed"
End %>