Saving reports

After making changes to a report using the ReportClientDocument class, you may want to save the modified report. Use the saveAs methods of the ReportClientDocument class to write to a report file (.rpt).

Note: The saveAs method throws a ReportSDKException object.
Saving a report to a file path
To save a new report to a file path accessible to the RAS server, specify the values of three parameters in the saveAs method:
  • The first parameter specifies the name of the report file to save to. Include the file extension (.rpt).
  • The second parameter accepts a String object that specifies the file path to save the report to.
  • The third parameter accepts an integer value that specifies the save options. See the ReportSaveAsOptions class for details.
void saveReportToFilepath(ReportClientDocument rcd) throws IOException, ReportSDKException
{
    rcd.saveAs("MyNewReport.rpt", "C:\\MyReports\\", ReportSaveAsOptions._overwriteExisting);
    rcd.close();
}
This list includes the classes used by the sample code:
  • com.crystaldecisions.sdk.occa.report.application.ReportClientDocument
  • com.crystaldecisions.sdk.occa.report.application.ReportSaveAsOptions
  • com.crystaldecisions.sdk.occa.report.lib.ReportSDKException
  • java.io.IOException
Saving a report to the Enterprise repository
To save a new report to an Enterprise repository, specify the values of three parameters in the saveAs method:
  • The first parameter specifies the name of the report file to save to. Do not include the file extension (.rpt).
  • The second parameter accepts an object that is either:
    • An IInfoObject object that represents the folder in the repository where you want to save the report to.
    • An Integer object that represents the ID (SI_ID) of the folder in the repository where you want to save the report to.
  • The third parameter accepts an integer value that specifies the save options. See the ReportSaveAsOptions class for details.
void saveReportToEnterprise(ReportClientDocument rcd) throws IOException, SDKException, ReportSDKException
{
    ISessionMgr sessionManager = CrystalEnterprise.getSessionMgr();
    IEnterpriseSession enterpriseSession = sessionManager.logon("username", "password", "hostname:port", "secEnterprise");
    
    IInfoStore iStore = (IInfoStore) enterpriseSession.getService("InfoStore");
    IInfoObjects objects = iStore.query("Select SI_ID From CI_INFOOBJECTS Where SI_NAME='My Reports' And SI_INSTANCE=0");   
    IInfoObject folder = (IInfoObject)objects.get(0);  
    
    rcd.saveAs("MyReport", folder.getID(), ReportSaveAsOptions._overwriteExisting);
    rcd.close();
}
This list includes the classes used by the sample code:
  • com.crystaldecisions.sdk.exception.SDKException
  • com.crystaldecisions.sdk.framework.IEnterpriseSession
  • com.crystaldecisions.sdk.framework.ISessionMgr
  • com.crystaldecisions.sdk.occa.infostore.IInfoObject
  • com.crystaldecisions.sdk.occa.infostore.IInfoObjects
  • com.crystaldecisions.sdk.occa.infostore.IInfoStore
  • com.crystaldecisions.sdk.occa.report.application.ReportClientDocument
  • com.crystaldecisions.sdk.occa.report.application.ReportSaveAsOptions
  • com.crystaldecisions.sdk.occa.report.lib.ReportSDKException
  • java.io.IOException