SAP Knowledge Base Article - Public

1702923 - How to find last page number using the Engine or Report Application Server .NET SDK?

Symptom

How to find last page number using the Engine or Report Application Server .NET SDK?

Environment

  • SAP Crystal Server 
  • SAP BusinessObjects BI Platform
  • Crystal Reports for Visual Studio

Resolution

Use following code for BOE/CRS:

string sampleReportName = "World Sales Report";
SessionMgr sessionMgr = new SessionMgr();
EnterpriseSession enterpriseSession;
EnterpriseService enterpriseService;
InfoStore infoStore;
InfoObjects infoObjects;
InfoObject infoObject;
ReportAppFactory reportAppFactory;
 // Logon to an Enterprise session.
enterpriseSession = sessionMgr.Logon("Administrator", "password", "localhost:6400", "secEnterprise");
// Query for the sample report from the Enterprise CMS.
enterpriseService = enterpriseSession.GetService("InfoStore");
infoStore = new InfoStore(enterpriseService);
infoObjects = infoStore.Query("Select SI_ID From CI_INFOOBJECTS Where SI_NAME='" + sampleReportName + "' And SI_INSTANCE=0");
infoObject = infoObjects[1];
 // Create an instance of the ReportAppFactory.
EnterpriseService tempService = enterpriseSession.GetService("", "RASReportFactory");
reportAppFactory = (ReportAppFactory)tempService.Interface;
// Open the report file for this sample.
rcd = reportAppFactory.OpenDocument(infoObject.ID, 0);
//Find last page.
int lastpage;    
lastpage = rcd.ReportSource.GetLastPageNumber(new CrystalDecisions.ReportAppServer.ReportDefModel.RequestContext());
 // Set the report source of the Crystal Report viewer to the instance of the report.
crystalReportViewer.ReportSource = rcd;


Use following code for CR for VS:

CrystalDecisions.CrystalReports.Engine.ReportDocument rpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rptClientDoc;

rpt.Load(@"c:\reports\CommandwithSub.rpt", OpenReportMethod.OpenReportByTempCopy); 
rptClientDoc = rpt.ReportClientDocument;

CrystalReportViewer CrystalReportViewer1 = new CrystalReportViewer();

// this sets the report to the session
if (!IsPostBack)
{
// engine
CrystalReportViewer1.ReportSource = rpt;
Response.Write("\nLast Page number is: " + rpt.FormatEngine.GetLastPageNumber(new ReportPageRequestContext()).ToString() + "\n");
//Find last page.
int lastpage;
lastpage = rptClientDoc.ReportSource.GetLastPageNumber(new CrystalDecisions.ReportAppServer.ReportDefModel.RequestContext());
Response.Write("\nRAS Last Page number is: " + lastpage.ToString() + "\n");
// RAS
//CrystalReportViewer1.ReportSource = rptClientDoc;
}
else
{
// engine
CrystalReportViewer1.ReportSource = Session["rpt"];
Response.Write("\nLast Page number is: " + rpt.FormatEngine.GetLastPageNumber(new ReportPageRequestContext()).ToString() + "\n");
//Find last page.
int lastpage;
lastpage = rptClientDoc.ReportSource.GetLastPageNumber(new CrystalDecisions.ReportAppServer.ReportDefModel.RequestContext());
Response.Write("\nRAS Last Page number is: " + lastpage.ToString() + "\n");
// RAS
//CrystalReportViewer1.ReportSource = Session["rptClientDoc"];
}

Also Note: same line works in a desktop WindowsForam app.

Keywords

bi40 bi net ras .net, cr for VS, GetLastPageNumber , KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , How To

Product

SAP Crystal Reports, developer version for Microsoft Visual Studio