Click here to Skip to main content
15,877,675 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a form that has Crystal Report Viewer on it. I also have a custom print button on it. Here is my code for the print button:

C#
protected void ButtonPrint_Click(object sender, EventArgs e)
        {
            CrystalReport.PrintOptions.PrinterName = GetDefaultPrinter();
            CrystalReport.PrintToPrinter(1, false, 1, 1);
        }

         string GetDefaultPrinter()
         {
          PrinterSettings settings = new PrinterSettings();
          foreach (string printer in PrinterSettings.InstalledPrinters)
            {
              settings.PrinterName = printer;
              if (settings.IsDefaultPrinter)
                  return printer;
                }
                return string.Empty;
            }
        private string GetDefaultprinterName()
        {
            throw new NotImplementedException();
        }
        }
    }


When the print button is clicked I get this error:

HTML
 Invalid report file path.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: CrystalDecisions.CrystalReports.Engine.LoadSaveReportException: Invalid report file path.

Source Error:


Line 61:         {
Line 62:             CrystalReport.PrintOptions.PrinterName = GetDefaultPrinter();
Line 63:             CrystalReport.PrintToPrinter(1, false, 1, 1);
Line 64:         }
Line 65: 


Source File: C:\Users\khopkins\Documents\visual studio 2010\Projects\SACSCOCLogin1.1\SACSCOCLogin1.1\ReportFormA.aspx.cs    Line: 63

Stack Trace:


[LoadSaveReportException: Invalid report file path.]
   CrystalDecisions.CrystalReports.Engine.EngineExceptionUtils.DoThrowException(String message, EngineExceptionErrorID id) +97
   CrystalDecisions.CrystalReports.Engine.ExceptionThrower.ThrowEngineException(String messageID, EngineExceptionErrorID id) +288
   CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename, OpenReportMethod openMethod, Int16 parentJob) +338
   CrystalDecisions.CrystalReports.Engine.ReportDocument.EnsureLoadReport() +179
   CrystalDecisions.CrystalReports.Engine.ReportDocument.get_FormatEngine() +172
   CrystalDecisions.CrystalReports.Engine.ReportDocument.PrintToPrinter(Int32 nCopies, Boolean collated, Int32 startPageN, Int32 endPageN) +81
   SACSCOCLogin1._1.ReportFormA.ButtonPrint_Click(Object sender, EventArgs e) in C:\Users\khopkins\Documents\visual studio 2010\Projects\SACSCOCLogin1.1\SACSCOCLogin1.1\ReportFormA.aspx.cs:63
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9752490
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +196
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724


What am I doing wrong? Why am I getting this error? Please Help!!!
Posted

error says "Invalid report file path."...
place break point at line no 63 in your file C:\Users\khopkins\Documents\visual studio 2010\Projects\SACSCOCLogin1.1\SACSCOCLogin1.1\ReportFormA.aspx.cs
attach debugger and check report file path, check the file is exist on that path or not...
set proper report path then try to print again
Happy Coding!
:)
 
Share this answer
 
Comments
Computer Wiz99 9-Apr-14 9:48am    
Aarti Meswania, Thanks for the infor but the path is correct and I just enabled the print button on CR Viewer. Your hard work for the information was helpful with the other reports.
try this way.. :)

C#
PrintDialog pDialog = new PrintDialog();

   Nullable<boolean> print = pDialog.ShowDialog();
   if (print == true)
   {


       string value1 = "abc";
       string value2= "foo";
       ReportDocument rd = new ReportDocument();
       rd.Load("ReportFile.rpt");
       rd.SetParameter("Parameter1", value1);
       rd.SetParameter("Parameter2", value2);

       rd.PrintOptions.PrinterName = pDialog.PrinterSettings.PrinterName;

       rd.PrintToPrinter(1, false,0,0);


   }</boolean>


reference

Crystal Report | Printing | Default Printer.. :)[^]
 
Share this answer
 

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