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!

ReportClientDocument Vs ReportDocument to export reports

Status
Not open for further replies.

MisterMo

Programmer
Mar 18, 2002
564
GB
I am trying to export my reports directly to PDF because with RAS you can only view the reports in HTML format and to print they have to be exported first.

I am currently using the ReportClientDocument object and everything works just fine, I do need the ReportDocument object to set the export functionallity in my code.

and here I hit a brick wall I am using Dot.Net 2003, CR10, CE 10 Embedded(RAS) and SQL2000 the database is set with windows integrated security.

what I don't understand is why ReportClientDocument has no issues about login and ReportDocument has.

Here is a code sample

Code:
ReportName = "C:\Crystal Reports\AnalysisReports\" & Request.Params("@ReportName").ToString
rptClientDoc.Load(ReportName, OpenReportMethod.OpenReportByTempCopy)

For i = 0 To rptClientDoc.ParameterFields.Count() - 1
            ParameterName = rptClientDoc.ParameterFields(i).Name
            myParameterFieldDefinition = rptClientDoc.DataDefinition.ParameterFields.Item(ParameterName)
            Value = Request.Params(rptClientDoc.ParameterFields(i).Name).ToString
            ParamValue = New ParameterFieldDiscreteValue
            ParamValue.Value = Value
            'rptClientDoc.SetParameterValue(ParameterName, ParamValue.Value)
            rptClientDoc.DataDefinition.ParameterFields(ParameterName).ApplyCurrentValues(ParamValue.Value)
        Next
        rptClientDoc.SetDatabaseLogon("User", "PWD", "SRV", "DB")


Crystalreportviewer1.DisplayGroupTree = False
Crystalreportviewer1.HasCrystalLogo = False
Crystalreportviewer1.ReportSource = rptClientDoc


when i try to view the report I get
"Unknown Query Engine Error".

I have the export code option ready but that fails too.

I am pretty sure it has to do with the fact that I have changed the 2 objects around but all my research has been fruitless so far.

I would really appreciate your help on this one.

Thank you in advance

Mo
 
I am using RAS SDK and using ReportClientDocument one can directly export to PDF. I have done it using Java and following is the method used.

private byte[] generateOther(ReportClientDocument reportDoc) throws Exception {
InputStream is = reportDoc.getPrintOutputController().export(ReportExportFormat.from_string((String) erd.getReportProperty("FormatCode")));
int numBytes = is.available();
byte[] b = new byte[numBytes];
is.read(b);
return b;
}
 
Thank RaufMohammed,
I have found something that does work at BO


and this is the code for my ASPX page:
Code:
Imports CrystalDecisions.ReportAppServer.ClientDoc
Imports CrystalDecisions.ReportAppServer.Controllers
Imports CrystalDecisions.ReportAppServer.DataDefModel
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports CrystalDecisions.ReportAppServer.DataSetConversion
Imports CrystalDecisions.ReportAppServer.ReportDefModel
Imports System.io


Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
Dim m_PrintOutputController As CrystalDecisions.ReportAppServer.Controllers.PrintOutputController
        Dim m_ByteArray As CrystalDecisions.ReportAppServer.CommonObjectModel.ByteArray
        Dim ParamValue As New ParameterFieldDiscreteValue
        Dim ParamValues As New CrystalDecisions.ReportAppServer.DataDefModel.Values
        Dim Value As String
        Dim ParameterName As String
        Dim i As Integer
        Dim strExportFile As String = "RasReport" & Request.Params("@TimeStamp").ToString() & ".pdf"
        Dim ReportName As String = "\\MyServer\C$\CrystalReports\AnalysisReports\MyReport.rpt"

        Try
            rptClientDoc.Open("rassdk://" & ReportName, 1)
            For i = 0 To rptClientDoc.DataDefController.DataDefinition.ParameterFields.Count() - 1
                ParameterName = rptClientDoc.DataDefController.DataDefinition.ParameterFields(i).Name
                Value = Request.Params(rptClientDoc.DataDefController.DataDefinition.ParameterFields(i).Name).ToString
                ParamValue = New ParameterFieldDiscreteValue
                ParamValue.Value = Value
                ParamValues.RemoveAll()
                ParamValues.Add(ParamValue)
                rptClientDoc.DataDefController.ParameterFieldController.SetCurrentValues("", ParameterName, ParamValues)
            Next
            m_PrintOutputController = rptClientDoc.PrintOutputController
            m_ByteArray = m_PrintOutputController.Export(CrReportExportFormatEnum.crReportExportFormatPDF)
            Dim exportPath As String = Server.MapPath(".") & "\exports\" & strExportFile
            m_ByteArray.Save(exportPath, True)
        Catch ex As Exception
            Response.Write(ex.Message)
        End Try
        Response.Redirect(".\exports\" & strExportFile)
    End Sub

I still would like to be able to output the report directly to stream but for the time being this will do just fine.




Mo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top