SAP Knowledge Base Article - Public

1490932 - How to move a subreport from one section of a main report to another using the RAS SDK for VS .NET

Symptom

  • A report is designed with a subreport in a particular section
  • At runtime, the subreport may need to be moved to a different section

Resolution

There are two possible solutions

  1.  
    1. Keep the subreport saved as a report on your hard drive and insert it into the main report as needed
//Get SubreportController object from ReportClientDocument object
SubreportController subRptController = reportClientDocument. getSubreportController();
String name = "GlobalSales.rpt";
String reportURL = "C:\MyReports\GlobalSales.rpt";
//Get the section into which the subreport will be added
ISection footerSection = reportClientDocument.getReportDefController() .findSectionByName
("FooterSection");
//Return the imported existing report as a SubReportClientDocument object
ISubreportClientDocument subRptClientDocument = subRptController. importSubreport(name,
 reportURL, footerSection);
}
catch (ReportSDKException e)
{
//do something here
}

2.         Move the subreport from section to section

boReportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
boReportDocument.Load(Server.MapPath("SimpleRCAPIReport.rpt"));
CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument boReportClientDocument = boReportDocument.ReportClientDocument;
CrystalDecisions.ReportAppServer.Controllers.ReportObjectController boReportObjectController = default(CrystalDecisions.ReportAppServer.Controllers.ReportObjectController);
boReportObjectController = boReportClientDocument.ReportDefController.ReportObjectController;
CrystalDecisions.ReportAppServer.ReportDefModel.ReportObjects boReportObjects = boReportObjectController.GetAllReportObjects;
CrystalDecisions.ReportAppServer.ReportDefModel.ReportObject boReportObject = default(CrystalDecisions.ReportAppServer.ReportDefModel.ReportObject);
boReportObject = boReportObjects.Item("Text1").Clone(true);

//Remove the old object
boReportObjectController.Remove(boReportObjects.Item("Text1"));

CrystalDecisions.ReportAppServer.ReportDefModel.Section boSection = default(CrystalDecisions.ReportAppServer.ReportDefModel.Section);
//pick the new section to put the object in
boSection = boReportClientDocument.ReportDefController.ReportDefinition.ReportFooterArea.Sections(0);

//add the object to the new section
boReportObjectController.Add(boReportObject, boSection);

See Also

RAS Developer Help

How to Use The RAS SDK .NET With In-Process RAS Server

RAS Sample Applications

Keywords

KBA , BI-DEV-NET-SDK , .NET SDK / COM SDK , How To

Product

Crystal Reports 2008 V1 ; SAP Crystal Reports XI R2