SAP Knowledge Base Article - Public

1684809 - How to change the format of a 'DateTime' field of a Crystal report at runtime using InProc RAS .NET SDK?

Symptom

How to change the format of a 'DateTime' field of a Crystal report at runtime using InProc RAS .NET SDK?

Environment

  • Crystal Reports 2008 SP3
  • Visual Studio 2008

Resolution

Here is the C# code to change the format of a DateTime field on the report.

 

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.ReportAppServer.Controllers;
using CrystalDecisions.ReportAppServer.ClientDoc;
using CrystalDecisions.ReportAppServer.DataDefModel;
using CrystalDecisions.ReportAppServer.ReportDefModel;
public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ISCDReportClientDocument rcd;
        CrystalDecisions.CrystalReports.Engine.ReportDocument rd = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
        rd.Load(Server.MapPath("Report1.rpt"));
        rcd = rd.ReportClientDocument;
        ISCRReportObject OldReportObject = rcd.ReportDefController.ReportDefinition.FindObjectByName("OrderDate1");
        ISCRReportObject NewReportObject = OldReportObject.Clone(false);
        ISCRFieldObject oFieldObject = (ISCRFieldObject)NewReportObject;
        oFieldObject.FieldFormat.DateTimeFormat.DateTimeOrder = CrDateTimeOrderEnum.crDateTimeOrderDateOnly;
        rcd.ReportDefController.ReportObjectController.Modify(OldReportObject, NewReportObject);
   
        rcd.Save();
        
        rcd.Close();
        CrystalReportViewer1.ReportSource = rd;
      
    }
}

Keywords

change date, crvs2010, cr4vs, , KBA , BI-DEV-NET-SDK , .NET SDK / COM SDK , How To

Product

Crystal Reports 2008 V1 ; SAP Crystal Reports, developer version for Microsoft Visual Studio