How to directly print rdlc report without showing PrintDialog() in C#?
c#, printing, rdlc
Solution
I just gave a quick look to a class I created to print directly and I think I took some ideas from this walkthrough: Printing a Local Report without Preview
Problem
I have an application where I have to print a `RDLC` report without showing the printDialog and using the default specified printer defined in the application. Below is my test implementaion code. ``` Microsoft.Reporting.WinForms.ReportViewer reportViewerSales = new Microsoft.Reporting.WinForms.ReportViewer(); Microsoft.Reporting.WinForms.ReportDataSource reportDataSourceSales = new Microsoft.Reporting.WinForms.ReportDataSource(); reportViewerSales.Reset(); reportViewerSales.LocalReport.ReportPath = @"Sales.rdlc"; reportDataSourceSales.Name = "SalesTableDataSet"; int i = 1; foreach (Product item in ProductSalesList) { dataset.CurrentSales.AddCurrentSalesRow(i, item.Name, item.Quantity.ToString(), item.Price.ToString(), item.Price.ToString()); i++; } reportDataSourceSales.Value = dataset.CurrentSales; reportViewerSales.LocalReport.DataSources.Add(reportDataSourceSales); dataset.EndInit(); reportViewerSales.RefreshReport(); reportViewerSales.RenderingComplete += new RenderingCompleteEventHandler(PrintSales); ``` And here is my Rendering Complete Method ``` public void PrintSales(object sender, RenderingCompleteEventArgs e) { try { reportViewerSales.PrintDialog(); reportViewerSales.Clear(); reportViewerSales.LocalReport.ReleaseSandboxAppDomain(); } catch (Exception ex) { } } ```