Problem Pringing Reports in C#

I have developed an app in c#, in visual that prints out word documents from a folder on a network. This works fine.

I have now added a crystal report to it, developed in CR10.

I have added it using Project > Add Existing Item.

I then used the toolbox to add the component ReportDocument to the form.

I want to print the report out after the word documents without previewing the report in a viewer.

The code below has been generated for the report, I have used the line application_Form___Overnight_Print1.PrintToPrinter(1,true,1,1); to try and print it

                       this.Application_Form_Print1.FileName = "";
                      this.Application_Form_Print1.InitReport += new (System.EventHandlerthis.Application_Form_Print1_InitReport);
                  // Form1

                 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
                 this.ClientSize = new System.Drawing.Size(600, 470);
                 this.Name = "Form1";

private void application_Form___Overnight_Print1_InitReport(object sender, System.EventArgs e)

            {            application_Form___Overnight_Print1.PrintToPrinter(1,true,1,1);


I run the report, the word documents print as normal, but no reports are printed to the printer, and I do not receive any error messages.

I have developed the report off a SQL database in CR10 using an odbc connection. The database has a userid and password.

Am I getting nothing because I have not connected to the database and how would I do this or is it something else?

I would also like to specify the printer name to print the reports from and wandered how to do this, the printers are networked and are in the format WSI-01/prn001

Can anybody help with this?


Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Here's some code snippets that may help.

It's also listed in the order you have to initialize things for crystal reports.
This code is for a report that directly connects to a database, and takes a parameter

ReportDocument crReport;
ReportDocument _crReport;
private Database crDatabase;
private Tables crTables;
private Table crTable;
private TableLogOnInfo crTableLogOnInfo = null ; //new TableLogOnInfo();
private ConnectionInfo crConnectionInfo = null; //new ConnectionInfo ();

this._crReport= new ReportDocument();
crTableLogOnInfo = new TableLogOnInfo();
crConnectionInfo = new ConnectionInfo ();

// for oracle, database name not needed
crConnectionInfo.ServerName = AppConstants.crServerName;
crConnectionInfo.DatabaseName = "";
crConnectionInfo.UserID = AppConstants.crUserName;
crConnectionInfo.Password = AppConstants.crUserPassword;

this.__crReport.Load( AppConstants.crReportPath );

SetReportLogon( ref ReportDocument rpt )

_crReport.SetParameterValue(name, value);

_crReport.PrintOptions.PrinterName = UserSettings.GetInstance().LocalReportPrinterName;

_crReport.PrintToPrinter(Copies, false, 1, 1);

private bool SetReportLogon( ref ReportDocument rpt )
                  if( !rpt.IsLoaded )
                        // error handling should be triggered here
                        System.Windows.Forms.MessageBox.Show("Unable to load report");
                        return false;

                        // This code works for both user tables and stored procedures
                        //Get the table information from the report
                        crDatabase = rpt.Database;
                        crTables = crDatabase.Tables;

                        //Loop through all tables in the report and apply the
                        //connection information for each table.
                        for (int i = 0; i < crTables.Count; i++)
                              crTable = crTables [i];
                              crTableLogOnInfo = crTable.LogOnInfo;
                              crTableLogOnInfo.ConnectionInfo = crConnectionInfo;

                              //If your DatabaseName is changing at runtime, specify
                              //the table location. For example, when you are reporting
                              //off of a Northwind database on SQL server
                              //you should have the following line of code:
                              //crTable.Location = AppConstants.crServerName  + "."  + crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1)  ;
                  catch( Exception e )
                        // TODO: wire this into an application error handler
                        System.Windows.Forms.MessageBox.Show( e.Message );
                        return false;
                  return true;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.