Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Guys, my problem is i want to print my report directly on form load but when i open my form so it's close automatically there is data in crystal report but it's not printing and form is close automatically i dont know why please tell me where i am wrong and one thing more i dont about
CrystalDecisions.CrystalReports.Engine.ReportDocument();
            rptDoc.Load(reportPath); i mean i dont know which path i need to put here please also suggest me this 

Thanks,

What I have tried:

<pre>private void PrintToPrinter()
        {
            PrintReport(System.Windows.Forms.Application.StartupPath + "\\CrystalReport1.rpt",
                "Send To OneNote 2013");
        }
        private void PrintReport(string reportPath, string PrinterName)
        {
            CrystalDecisions.CrystalReports.Engine.ReportDocument rptDoc =
                                new CrystalDecisions.CrystalReports.Engine.ReportDocument();
            rptDoc.Load(reportPath);

            CrystalDecisions.Shared.PageMargins objPageMargins;
            objPageMargins = rptDoc.PrintOptions.PageMargins;
            objPageMargins.bottomMargin = 100;
            objPageMargins.leftMargin = 100;
            objPageMargins.rightMargin = 100;
            objPageMargins.topMargin = 100;
            rptDoc.PrintOptions.ApplyPageMargins(objPageMargins);
            rptDoc.PrintOptions.PrinterName = "Microsoft XPS Document Writer";
            rptDoc.PrintToPrinter(1, false, 0, 0);
        }
Posted
Comments
[no name] 8-Jan-17 11:00am    
Learn how to use the debugger to debug your code.
"i dont know which path", if you do not know, how would you expect us to know?
Sunasara Imdadhusen 9-Jan-17 5:08am    
May help this one http://stackoverflow.com/questions/22006107/how-to-automatically-print-crystal-reports-with-default-printer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900