When I call ExportToDisk(). In some machine do well. But in some machine throw the exception.
Exceptoion
This field name is not known. Error in File C:\Windows\TEMP\RPTH010_Report01 {C0D0E863-1741-4917-A455-B23347EA4FD6}.rpt: Error in formula <填單日期>. 'numberVar RocDateNumber := {RPTH010_Report01.D01_APLDATE};' This field name is not known.
This field name is not known. Error in File C:\Windows\TEMP\RPTH010_Report01 {C0D0E863-1741-4917-A455-B23347EA4FD6}.rpt: Error in formula <填單日期>. 'numberVar RocDateNumber := {RPTH010_Report01.D01_APLDATE};' This field name is not known.
stack trace
CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e) CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext) CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext) CrystalDecisions.CrystalReports.Engine.FormatEngine.Export(ExportRequestContext reqContext) CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToDisk(ExportFormatType formatType, String fileName) JcsWebSolution.Report.CRDocument.SaveToDisk() mOffice.Models.Report.ASSET.RPTH010_Report01.PrintReport() mOffice.Models.Report.ReportBase.PrintProcess()
My system
- CrystalDecisions.CrystalReports.Engine.dll, v10.5.3700.0
- CrystalDecisions.Shared.dll, v10.5.3700.0
- Window Server 2012 R2
- Visual Studio 2013
I try to fixed the bug by
- Reinstall crystal report runtime SP12.
- Checking the font is in system.
And I try to print a report without formula and it can export well. And I add the concat string formula it just broken.
My code
public class result
{
public string { get; set;}
}
public bool DoExport()
{
List<result> test = new List<result>();
test.Add(new result { test = "123" });
DataTable input = ListToDataTable(test);
input.TableName = "test";
m_RptDataSet.Tables.Add(input);
ReportDocument m_ReportDocument = new ReportDocument();
m_ReportDocument.Load(HttpContext.Current.Server.MapPath("~/RPT/test.rpt"));
m_ReportDocument.SetDataSource(input);
m_ReportDocument.ExportToDisk(ExportFormatType.PortableDocFormat, "test.pdf");
m_ReportDocument.Close();
m_ReportDocument.Dispose();
m_ReportDocument = null;
}
public DataTable ListToDataTable<T>(List<T> list)
{
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(T));
DataTable dt = new DataTable();
object[] values;
for (int i = 0; i < props.Count; i++)
{
PropertyDescriptor prop = props[i];
dt.Columns.Add(prop.Name, prop.PropertyType);
}
foreach (T item in list)
{
values = new object[props.Count];
for (int i = 0; i < values.Length; i++)
{
values[i] = props[i].GetValue(item);
}
dt.Rows.Add(values);
}
return dt;
}
concat string formula
{RPTH040_Test.test} + " test Function"
But in other machine just fine. Does anyone has the same problem?
Updated
I test a new report which have 3 records without formula. I find that the report can export, but does not show records. So I guess the main reason is that SetDataSource() doesn't work in my machine(windows 2012 R2). I try to add the code to Web.config.
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
It still not work. Does anyone know about this?
null
? – craig<startup useLegacyV2RuntimeActivationPolicy="true"><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
to Web.config. It still not work. Does anyone know about this? – Milkker