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://es.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.
Hristo,
Thank you for your reply. I don't think that solution will work for my application. The report is built from a sql query from the parameters entered by the user. I'm not totally against using the xam reportViewer or even a HTML report viewer. I've tried the silverlight project but haven't been able to get it running either. Do you have any asp.NET solutions that I could view as an example that may closely resemble my own? My silverlight project 'DirectoryReport' using xamReportViewer is set up as follows.
Silverlight 5
The MainPage.xaml and App.xaml is in the DirectoryReport section
The Report.igr, Report.svc, TestPage.html/aspx, and Web.Config are in the DirectoryReport.Web section
My trouble with this way is I haven't figured out how to link the .igr report to the report viewer while they are in different sections. I will provide code below.
<ig:XamReportViewer x:Name="igReportViewer" VerticalAlignment="Center" HorizontalAlignment="Center" Height="430" Width="646">
<ig:XamReportViewer.RenderSettings>
<ig:ClientRenderSettings DefinitionUri="DirectoryReport.Web;component/EmpReport.igr" />
</ig:XamReportViewer.RenderSettigns>
</ig:XamReportViewer>
I've tried many different combinations of the relative path and no luck yet. When I run the application I get the error "Cound not find report definition /DirectoryReport.Web;component/EmpReport.igr"
My report build action is set to Content and Always copy to Output Directory