or
{"Message":"An error has occurred.","ExceptionMessage":"Object reference not set to an instance of an object.","ExceptionType":"System.NullReferenceException","StackTrace":" at Telerik.Reporting.ExcelRendering.RenderingItem.Render(IWorksheet worksheet, TableLayoutInfo layoutInfo)\r\n at Telerik.Reporting.ExcelRendering.RenderingItemContainer.RenderInternal(IWorksheet worksheet, TableLayoutInfo layoutInfo)\r\n at Telerik.Reporting.ExcelRendering.Table.RenderInternal(IWorksheet worksheet, TableLayoutInfo layoutInfo)\r\n at Telerik.Reporting.ExcelRendering.RenderingItem.Render(IWorksheet worksheet, TableLayoutInfo layoutInfo)\r\n at Telerik.Reporting.ExcelRendering.RenderingItemContainer.RenderInternal(IWorksheet worksheet, TableLayoutInfo layoutInfo)\r\n at Telerik.Reporting.ExcelRendering.Section.RenderInternal(IWorksheet worksheet, TableLayoutInfo layoutInfo)\r\n at Telerik.Reporting.ExcelRendering.RenderingItem.Render(IWorksheet worksheet, TableLayoutInfo layoutInfo)\r\n at Telerik.Reporting.ExcelRendering.Group.RenderInternal(IWorksheet worksheet, TableLayoutInfo layoutInfo)\r\n at Telerik.Reporting.ExcelRendering.RenderingItem.Render(IWorksheet worksheet, TableLayoutInfo layoutInfo)\r\n at Telerik.Reporting.ExcelRendering.RenderingItemContainer.RenderInternal(IWorksheet worksheet, TableLayoutInfo layoutInfo)\r\n at Telerik.Reporting.ExcelRendering.Report.RenderInternal(IWorksheet worksheet, TableLayoutInfo layoutInfo)\r\n at Telerik.Reporting.ExcelRendering.RenderingItem.Render(IWorksheet worksheet, TableLayoutInfo layoutInfo)\r\n at Telerik.Reporting.ExcelRendering.Report.Render(IWorkbook workbook)\r\n at Telerik.Reporting.ExcelRendering.Excel97.ExcelReport.Telerik.Reporting.Processing.IRenderingExtension.Render(Report report, Hashtable renderingContext, Hashtable deviceInfo, CreateStream createStreamCallback, EvaluateHeaderFooterExpressions evalHeaderFooterCallback)\r\n at Telerik.Reporting.Processing.ReportProcessor.RenderCore(ExtensionInfo extensionInfo, IList`1 reports, Hashtable deviceInfo, IRenderingContext renderingContext, CreateStream createStreamCallback)\r\n at Telerik.Reporting.Processing.ReportProcessor.ProcessAndRender(String format, ReportSource reportSource, Hashtable deviceInfo, IRenderingContext renderingContext, CreateStream createStreamCallback)\r\n at Telerik.Reporting.Processing.ReportProcessor.ProcessAndRenderStateless(String format, ReportSource reportSource, Hashtable deviceInfo, IRenderingContext renderingContext, CreateStream createStreamCallback)\r\n at Telerik.Reporting.Processing.ReportProcessor.RenderReport(String format, ReportSource reportSource, Hashtable deviceInfo)\r\n at CPSReporting.TelerikCPSReportProcessor.RenderExcelReport(CPSReportDefinition reportDefinition) in c:\\Code\\CPS_SVN_REPO\\CPSReporting\\trunk\\TelerikCPSReportProcessor.cs:line 78\r\n at CreditPoint.Web.Controllers.WebAPI.ReportController.PrepResponse(HttpRequest request) in c:\\Code\\CPS_SVN_REPO\\Web\\branches\\RB-4.6\\Controllers\\WebAPI\\ReportController.cs:line 69\r\n at CreditPoint.Web.Controllers.WebAPI.ReportController.Post() in c:\\Code\\CPS_SVN_REPO\\Web\\branches\\RB-4.6\\Controllers\\WebAPI\\ReportController.cs:line 27\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.b__c(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.<>c__DisplayClass5.b__4()\r\n at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)"}
InstanceReportSource instanceReportSource = new InstanceReportSource();
XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
xmlReaderSettings.IgnoreWhitespace = true;
ReportXmlSerializer serializer = new ReportXmlSerializer();
XmlReader primaryReportXmlReader = XmlReader.Create(reportDefinition.PrimaryReport.TemplateLocation, xmlReaderSettings);
Telerik.Reporting.Report primaryReport = (Telerik.Reporting.Report)serializer.Deserialize(primaryReportXmlReader);
primaryReportXmlReader.Close();
this.SetConnectionStrings(ref primaryReport, reportDefinition.ConnectionString);
instanceReportSource.ReportDocument = primaryReport;
if (reportDefinition.PrimaryReport.ReportParameters != null)
{
foreach (KeyValuePair<
string
, object> item in reportDefinition.PrimaryReport.ReportParameters)
instanceReportSource.Parameters.Add(this.CreateParameter(item.Key, item.Value));
}
foreach (CPSReport cpsSubReport in reportDefinition.SubReports)
{
XmlReader xmlReader = XmlReader.Create(cpsSubReport.TemplateLocation, xmlReaderSettings);
Telerik.Reporting.Report subReportInstance = (Telerik.Reporting.Report)serializer.Deserialize(xmlReader);
xmlReader.Close();
this.SetConnectionStrings(ref subReportInstance, reportDefinition.ConnectionString);
Telerik.Reporting.SubReport subReport = primaryReport.Items.Find(cpsSubReport.ReportName, true).FirstOrDefault() as Telerik.Reporting.SubReport;
ReportSource subReportSource_Type = subReport.ReportSource;
InstanceReportSource subReportSource_Instance = new InstanceReportSource();
subReportSource_Instance.ReportDocument = subReportInstance;
foreach(Telerik.Reporting.Parameter param in subReportSource_Type.Parameters)
subReportSource_Instance.Parameters.Add(param);
subReport.ReportSource = subReportSource_Instance;
}
Hashtable settings = new Hashtable() {
{ "UseNativePageHeader", false },
{ "UseNativePageFooter", true },
{ "ShowGridLines", false }
};
//Exception thrown here:
RenderingResult result = _reportProcessor.RenderReport("XLS", instanceReportSource, settings);
return result.DocumentBytes;
But, I find that that when I use identity impersonation to allow this code to work (configured via web.config), the impersonated account needs admin rights on the web server. Our network admin would prefer to give specific rights to this account, vs. just adding to the administrators group. Can you tell us what those would be? He thought maybe a temp file was being created somewhere on the server to support the printing.
Thanks in advance!
public
Stream GetReportBytes(Guid studyId,
string
userName)
{
ReportProcessor reportProcessor =
new
ReportProcessor();
Telerik.Reporting.InstanceReportSource instanceReportSource =
new
Telerik.Reporting.InstanceReportSource();
ProjectReport reportToExport =
new
ProjectReport();
reportToExport.ReportParameters[0].Value = studyId.ToString();
reportToExport.ReportParameters[1].Value = userName;
instanceReportSource.ReportDocument = reportToExport;
RenderingResult result = reportProcessor.RenderReport(
"PDF"
, instanceReportSource,
null
);
return
new
MemoryStream(result.DocumentBytes);
}
MainChart.PlotArea.Appearance.FillStyle.FillSettings.BackgroundImage =
"~/Images/ci_bg.png"
;