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:
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:
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!!!