Symptom
Reproducing the Issue
Resolution
sample code:
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.ReportAppServer.ClientDoc;
//CR Declarations
ReportDocument m_boReportDocument;
ISCDReportClientDocument m_boReportClientDocument;
CrystalDecisions.ReportAppServer.ReportDefModel.Section m_boSection;
CrystalDecisions.ReportAppServer.DataDefModel.SpecialField m_boSpecialField;
CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject m_boFieldObject;
//create a new ReportDocument
m_boReportDocument = new ReportDocument();
//load the RPT file
m_boReportDocument.Load("..\\..\\AddSpecialField.rpt");
//access the ReportClientDocument in the ReportDocument (EROM bridge)
m_boReportClientDocument = m_boReportDocument.ReportClientDocument;
//first determine which section to add the special field to -
//in this case the page header section
m_boSection = m_boReportClientDocument.ReportDefController.ReportDefinition.PageHeaderArea.Sections[0];
//create the special field
m_boSpecialField = new CrystalDecisions.ReportAppServer.DataDefModel.SpecialField();
//set the type of field
m_boSpecialField.SpecialType = CrystalDecisions.ReportAppServer.DataDefModel.CrSpecialFieldTypeEnum.crSpecialFieldTypePrintDate;
//assign the specialfield to the fieldObject
m_boFieldObject = new CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject();
//it is necessary to use the getName method here rather than the getFormulaForm method because special fields are defined in Crystal Reports
//without {} around them - but the formulaform automatically adds the {} around them which leads to an "Invalid Field Object" error.
//e.g FormulaForm = {PrintDate} Name = PrintDate
//If you type the above in a formula inside the Crystal Report Designer, the one with the {} will not work.
m_boFieldObject.DataSourceName = m_boSpecialField.Name;
m_boFieldObject.FieldValueType = m_boSpecialField.Type;
//set the location of the field object
m_boFieldObject.Left = 10000; // 1 would be left corner
m_boFieldObject.Top = 1;
m_boFieldObject.Width = 1080;
m_boFieldObject.Height = 216;
//add the special field to the report
m_boReportClientDocument.ReportDefController.ReportObjectController.Add(m_boFieldObject, m_boSection, -1);
//display in reportviewer
crystalReportViewer1.ReportSource = m_boReportDocument;
See Also
Keywords
How add specialfield report Crystal Reports .NET inproc RAS SDK , KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , How To