So, I've been on a quest to replace crystal Reports. In VS 2010, I've found a workable client side reporting solution in RDLC. Now, I know its going to be an uphill battle to produce Avery style labels with RDLC but I'm going uphill 75MB lighter.
The real motivation for this reporting switch is my next version of Digital Rockhound's Companion software is going to be a download users can buy. I'll trimmed down the files my software uses. I'm ditching my street level arcview shapefiles dated circa 1995 for Google/Bing/OSM online maps. Last piece is really the reporting engine.
In a little under 3 hours, I was able to add in a basic grid RDLC report into DRC 3.0 and get the report to display in the report viewer, print directly to a local printer, and render to a PDF and word file formats.
Resources that helped me with RDLC reports:
Brian Hartman's code to manually print a RDLC report. Code sample Here.
MSDN: Walkthrough: Printing a Local Report without Preview
Get this error attempting to print a localreport without a RDLC source.
The report definition for report 'xxx' has not been specified.
A couple of useful stackoverflow posts:
Code to convert RDLC to a PDF
Code to convert RDLC to Word.
Article from dotnetsoldier blog
My code to render a simple RDLC report to a word Doc and then launch word:
var rds = new ReportDataSource("DataSet1", args.ReportData); var report = new LocalReport { ReportEmbeddedResource = string.Format("DRC.RDLC.{0}.rdlc", args.ReportName) }; report.DataSources.Add(rds); // ReSharper disable RedundantAssignment string encoding = String.Empty; string mimeType = String.Empty; string extension = String.Empty; // ReSharper restore RedundantAssignment Warning[] warnings = null; string[] streamids = null; string wordDocName = args.PDFFileName.ToLower().Replace(".pdf", ".doc"); byte[] bytes= report.Render("WORD", null, out mimeType, out encoding, out extension, out streamids, out warnings); using (var fs = new FileStream(wordDocName, FileMode.Create)) { fs.Write(bytes, 0, bytes.Length); } if (File.Exists(wordDocName)) System.Diagnostics.Process.Start(wordDocName);
//My code to print RDLC locally: var rds = new ReportDataSource("DataSet1", args.ReportData); var report = new LocalReport { ReportEmbeddedResource = string.Format("DRC.RDLC.{0}.rdlc", args.ReportName) }; report.DataSources.Add(rds); var reportPrintDoc = new ReportPrintDocument(report) { PrinterSettings = {PrinterName = Properties.Settings.Default.DRC_Printer} }; reportPrintDoc.Print();
No comments:
Post a Comment