I'm attempting to generate a report in a .NET console application using the following code:
This executes without error, however the output file testReport.pdf is just an empty file (0 bytes) and Adobe Reader displays an error when I try to open it. The TestReport.igr is just a report with an "I AM A REPORT" text block in it. There are no databindings or parameters in it yet.
Am I missing something? This will be an application that runs nightly with no user interaction. I need to be able to generate reports and save them to file. Is there a better way of going about this?
Hello Tyler,
There are different reasons that could cause your issue. One possible reason could be if you have not permissions to that folder, another possible reasons could be if you try to export your .pdf file, before finishing the report. In that case you could handle this exception with try / catch - “This operation requires a viewer with a report that has finished loading.” Looking at your code, I suppose that the most probable reason for your issue, could be if you didn`t include your UltraReportViewer in the control collection. It is very easy to reproduce this scenario. Please take a look on attached video file for more details. Here is the code that I used in my samples:
UltraReportViewer rv = new UltraReportViewer();
Infragistics.Win.UltraWinReportViewer.ClientRenderSettings clientRenderSettings11 = new Infragistics.Win.UltraWinReportViewer.ClientRenderSettings();
Controls.Add(rv);
rv.AutoRender = true;
rv.CurrentPage = 0;
rv.IsParametersPaneVisible = true;
rv.MergedDictionary = null;
rv.Name = "RV1";
rv.PageFit = Infragistics.Controls.Reports.PageFit.ZoomScale;
clientRenderSettings11.DefinitionStream = null;
clientRenderSettings11.DefinitionUri = new System.Uri("/Test 5555;component/Report1.igr", System.UriKind.Relative);
rv.RenderSettings = clientRenderSettings11;
rv.TabIndex = 0;
rv.ZoomScale = 100;
IClientExporter exporter = rv.CreateExporter(clientRenderSettings11.DefinitionUri);
FileStream fileStream = new FileStream("..\\..\\TTTT.pdf", FileMode.Create);
exporter.ExportCompleted += new EventHandler<ExportCompletedEventArgs>(exporter_ExportCompleted);
exporter.ExportAsync(fileStream, "PDF");
Tyler Olivier said:This will be an application that runs nightly with no user interaction. I need to be able to generate reports and save them to file. Is there a better way of going about this?
There are many approaches to solve this task. You could create application which using continues loop thread to create your reports, another possible solution could be with windows service (this is my favorite approach). In this case, please do not forget to allow the service to interact with desktop. Another solution could be with WCF service or Windows Tray Application and so on. But maybe the easiest way to solve this task, could be if you are using “Task Sheduler” of your OS or Windows Tray Application.
Please take a look on attached video file where I used two different approaches (with threads and Windows Service) Of course these approaches are more complicate but they have another advantages. Please note that in both scenarios my UltraReportViewer is include in control collections.
Let me know if you have any questions.
In previous video file I missed to show you the issue with Control collection. Please take a look for more details in that video
Let me know if you have any questions
this is the sample:.
I made small sample for you. In this sample, I used simple approach with Windows Tray Application. Please take a look on attached sample and video file for more details and if you have any questions, feel free to write me
Regards
Thank you for your help. I've changed my code to this:
public void ExportReport(string reportName, string reportPath, Dictionary<string, object> reportParams)
{
string initializePack = System.IO.Packaging.PackUriHelper.UriSchemePack;
Uri reportUri = new Uri("pack://application:,,,/Reports/" + reportName + ".igr");
UltraReportViewer reportViewer = new UltraReportViewer();
ClientRenderSettings clientRenderSettings = new ClientRenderSettings();
this.Controls.Add(reportViewer);
reportViewer.AutoRender = true;
reportViewer.CurrentPage = 0;
reportViewer.MergedDictionary = null;
reportViewer.Name = "RV1";
//reportViewer.RenderSettings.DefinitionUri = reportUri;
clientRenderSettings.DefinitionStream = null;
clientRenderSettings.DefinitionUri = reportUri;
reportViewer.RenderSettings = clientRenderSettings;
using (IClientExporter exporter = reportViewer.CreateExporter(clientRenderSettings.DefinitionUri))
using (FileStream fileStream = new FileStream(reportPath, FileMode.Create))
if (reportParams != null)
List<ParameterValue> paramsList = new List<ParameterValue>();
foreach (KeyValuePair<string, object> param in reportParams)
paramsList.Add(new ParameterValue { Name = param.Key, Value = param.Value });
}
exporter.Parameters = paramsList;
private void exporter_ExportCompleted(object sender, ExportCompletedEventArgs e)
However I am still getting a 0 byte Report, but no errors. Do I need something in the exporter_ExportCompleted event handler? I didn't see anything in your example.