2

I have used to Microsoft Report wizard to create a Report (a delivery receipt) for a Transport application. Now I want the end user to be able to print the receipt as soon as he clicks a button. The problem is that on click of a button the report is first loaded and then he has to select the print button. I want to automate the process of loading and printing. The guy has to print about 200-300 receipts a day and it is very time consuming to follow the current method!

I am developing using C# and working on Microsoft visual studio 2010. I am working on winForms desktop application and the report is local

Saurabh
  • 1,055
  • 14
  • 38
  • This is a duplicate of [Automatically print SSRS report?](http://stackoverflow.com/questions/480723/automatically-print-ssrs-report) – Will A Jun 09 '11 at 18:53
  • I am working on a desktop application. I cannot add the Web reference – Saurabh Jun 09 '11 at 19:15
  • Please specify what report type and database you are connecting to, as many people think it is a SSRS report on SQL Server. – Dour High Arch Jun 09 '11 at 19:18
  • The report is local and not on a report server. It is generated using data from a DataSet.xsd. I am using reportviewer to view the report inside a form! – Saurabh Jun 09 '11 at 19:21

2 Answers2

2

Have a look at this: http://msdn.microsoft.com/en-us/library/ms252091.aspx

It generates a file and prints that to the default printer. I have used this a derivative of this before, and it worked OK (if I remember correctly) but I had to add some code to clear down the EMF file once printed.

Seems like a lot of code to do something so simple, but it may help?

CYMR0
  • 566
  • 6
  • 16
  • @CYMR0: I tried the same thing but i seem to get a error message! – Saurabh Jun 10 '11 at 19:32
  • @CYMR0: In that code, cant i just give in the report and remove the DataTable LoadSalesData() function and report.DataSources.Add(new ReportDataSource("Sales", LoadSalesData())); line in the Run function? – Saurabh Jun 10 '11 at 19:35
  • Error is on line: report.Render("Image", deviceInfo, CreateStream, out warnings); – Saurabh Jun 10 '11 at 19:44
  • The report is bringing in data from a sales table. You can get rid of it I think, but you would need to bring in data some other way. What error message are you getting on that line?? – CYMR0 Jun 10 '11 at 20:16
  • @CYMR0: Thanks a ton mate! It worked like a gem! Just one more thing, while deployment should this report be copied to output directory (because i need to specific the file path in the code)? – Saurabh Jun 11 '11 at 20:16
  • @saurabh - glad I could help. Don't know what you mean about the deployment - if you're deploying as a clickonce application or just distributing the exe that should be enough - although you'll need to make sure they have the reportviewer installed (which clickonce does I think). – CYMR0 Jun 11 '11 at 20:24
-2

If you are using crystal report, you could use ReportDocument.PrintToPrinter method. Have a look at this.

FIre Panda
  • 6,537
  • 2
  • 25
  • 38