I've been scratching my head at this for a few months now. I've written a company directory for my job and one feature was reporting capabilities of an org structure.
The program is written in asp.NET with .NET framework 4.5
I've created the .igr report and everything shows perfect when I run it locally or preview the igr report.
It works with two parameters that are chosen from dropdown boxes on the page and the report is generated once a submit button is clicked.
I only need the report to be downloaded directly after the button has been clicked, therefore my reason for not usign and report viewers.
Code below with error message pulled from server script. (Hopefully no typing errors, I have to go between classified and unclassified computers)
Private Sub toPDF(ByVal parameterList As IEnumerable(Of ParameterValue))
Dim reportUri = New Uri(“/DirectoryASPForms;component/Emp.igr”, UriKind.Relative)
Dim exporter = ServerExporterFactory.CreateExporter(reportUri)
Using (exporter)
Dim MemoryStream As New MemoryStream
exporter.Parameters = parameterList
exporter.Export(MemoryStream, “PDF”)
SendStreamToResponse(MemoryStream, “EmployeeReport.pdf”, “application/pdf”)
MemoryStream.Close()
End Using
End Sub
Private Sub SendStreamToResponse(stream As MemoryStream, filename As String, reportType As String)
Dim reportBuffer = stream.ToArray()
Response.AddHeader(“Content-Length”, reportBuffer.Length.ToString())
Response.ContentType = reportType
Response.AddHeader(“Expires”, “0”)
Response.AddHeader(“Cache-Control”, ”must-revalidate, post-check=0, pre-check=0”)
Response.AddHeader(“Pragma”, “public”)
Response.AddHeader(“Content-Disposition”, “attachment; filename =” + filename)
Response.BinaryWrite(reportBuffer)
Response.Flush()
Response.End()
Error:
Infragistics.Reports.Server.ReportProcessorException: An error occurred while processing the Report. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at Infragistics.Reports.Engine.ServiceModelMefDiscoverer.Initialize(IServiceModelManager serviceModel)
at Infragistics.Reports.Server.ServerExporter.CreateLocalEngine(IEnumberable`1 dataSources, IReportInstanceSession& session)
at Infragistics.Reports.Server.ServerExporter.Export(Stream output, String exportFormat)
--- End of inner stack trace ---
at DirectoryASPForms.ReportGen.toPDF(IEnumerable`1 parameterList)’);
Hi Robert,
Thank you for posting in the Infragistics community !
Please have a look at the following online sample:
http://ko.infragistics.com/samples/aspnet/infragistics-documents/export-to-pdf-or-xps that demonstrates the exaxt goal you follow - how to create a report and download it, without the need to preview it in the page. You can compare your code to the recommended approach used.
If error still exists please provide some more details so that I can try to reproduce and investigate it on my side. Any working sample will be highly appreciated. Looking forward to hearing from you.