cancel
Showing results for 
Search instead for 
Did you mean: 

Export Report to PDF

Former Member
0 Kudos

Hi,

I'm very new to this fourm and on a steep learning curve.

I'm querying the RAS for a report and using the reportAppFactory object and reportClientDocument.OpenDocument to open the report. I'm setting database logon to tables and any subreports. Finally I set the parameter value and then want to export the report to a bytearray in a PDF format. This last step is where I'm having problems. On the PrintOutputController.Export call I keep getting an error, "Failed to open report".

Am I going about this the wrong way? Can anyone point me in the right direction?

Many Thanks.


CrystalDecisions.CrystalReports.Engine.ReportDocument rptDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
SessionMgr sessionMgr = new SessionMgr();
EnterpriseSession enterpriseSession = sessionMgr.LogonWithToken(sToken);
EnterpriseService enterpriseService = enterpriseSession.GetService("InfoStore");
InfoStore infoStore = new InfoStore(enterpriseService);

querystring = "Select SI_CUID, SI_DESCRIPTION From CI_INFOOBJECTS Where SI_PROGID='CrystalEnterprise.Report' And SI_NAME = '" + sReportName.ToString() + "'";

InfoObjects infoObjects = infoStore.Query(querystring);
InfoObject infoObject = infoObjects[1];

EnterpriseService tempService = enterpriseSession.GetService("", "RASReportFactory");
ReportAppFactory reportAppFactory;
reportAppFactory = (ReportAppFactory)tempService.Interface;

ReportClientDocument reportClientDocument = new ReportClientDocumentClass();
reportClientDocument = reportAppFactory.OpenDocument(infoObject.ID, 0);


CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo cnInfo = (CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo)reportClientDocument.DatabaseController.GetConnectionInfos(null)[0].Clone(true);


PropertyBag propertyBag = new PropertyBagClass();
                
propertyBag.EnsureCapacity(5);
propertyBag["Database DLL"] = "crdb_odbc.dll";
propertyBag["QE_DatabaseType"] = "ODBC (RDO)";
propertyBag["QE_ServerDescription"] = "ODBC - Xtreme Sample Database 10";
propertyBag["QE_SQLDB"] = true;
propertyBag["Server Name"] = sDbDSN;
                
cnInfo.Attributes = propertyBag;
cnInfo.UserName = sDbUsername;
cnInfo.Password = sDbPassword;
cnInfo.Kind = CrConnectionInfoKindEnum.crConnectionInfoKindSQL;


foreach (CrystalDecisions.ReportAppServer.DataDefModel.Table oTable in reportClientDocument.Database.Tables)
                {
                    oTable.ConnectionInfo = cnInfo;
                }

foreach (String tempSubReportName in reportClientDocument.SubreportController.QuerySubreportNames())
                {
CrystalDecisions.ReportAppServer.DataDefModel.Database database = reportClientDocument.SubreportController.GetSubreportDatabase(tempSubReportName);

                    foreach (CrystalDecisions.ReportAppServer.DataDefModel.Table table_old in database.Tables)
                    {
CrystalDecisions.ReportAppServer.DataDefModel.Table table_new = new CrystalDecisions.ReportAppServer.DataDefModel.TableClass();

table_new.Name = table_old.Name;
table_new.ConnectionInfo = cnInfo;

reportClientDocument.SubreportController.SetTableLocation(tempSubReportName, table_old, table_new);
                    }
                }



ParameterFieldDiscreteValue paramValue = new ParameterFieldDiscreteValue();
                paramValue.Value = sReportParameter;

                Values val = new Values();
                val.Add(paramValue);

                reportClientDocument.DataDefController.ParameterFieldController.SetCurrentValue(sReportName, reportClientDocument.DataDefinition.ParameterFields[0].Name, paramValue);

                PrintOutputController rasPrintOutputController = reportClientDocument.PrintOutputController;



                if (reportClientDocument.IsOpen)
                {
                    ByteArray tempByteArray = rasPrintOutputController.Export(CrReportExportFormatEnum.crReportExportFormatPDF, 1);
                    Byte[] byteStreamOutput = tempByteArray.ByteArray;

                    reportClientDocument.Close();
                    GC.Collect();

                    Response.Clear();
                    Response.AddHeader("content-disposition", "inline;filename=untitled.pdf");
                    Response.ContentType = "application/pdf";
                    Response.BinaryWrite(byteStreamOutput);
                    Response.End();
                }


Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello, Shane;

You did not mention which version you were using. There is a Developrs Help for BusinessObjects XI R2

You will find Report Application Server samples [here|http://devlibrary.businessobjects.com/BusinessObjectsXIR2SP2/en/en/RAS_SDK/sampleList.htm].

There is code for exporting to PDF using managed RAS [here|http://devlibrary.businessobjects.com/BusinessObjectsXIR2SP2/en/en/RAS_SDK/rassdk_net_doc/doc/rassdk_net_doc/html/SampleCode10.html].

And antoher sample for unmanaged RAS [here|http://devlibrary.businessobjects.com/BusinessObjectsXIR2SP2/en/en/RAS_SDK/rassdk_net_doc/doc/rassdk_net_doc/html/SampleCode11.html].

You can check your Query in QueryBuilder to be sure it is bringing back the object you expect to use.

Elaine

Answers (0)