Hi,
I have 2 questions:
When I click on print button for my report, I recive following error.
Invalid report file path. from this line:rd.PrintToPrinter(1, false, 0, 1);
What do i do?
And for printing my report in asp.net in crystalreprot viewer, when I refresh my page, print button does not work properly, why?
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Reporting;
public partial class mojavez_Report : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
ReportDocument rd = new ReportDocument();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
getdata();
}
}
void getdata()
{
con.Open();
SqlCommand com = new SqlCommand("SELECT DISTINCT MajorName FROM Majores ", con);
SqlDataAdapter da = new SqlDataAdapter(com);
DataTable dt = new DataTable();
da.Fill(dt);
DropDownList3.DataSource = dt;
DropDownList3.DataTextField = "MajorName";
DropDownList3.DataValueField = "MajorName";
DropDownList3.SelectedIndex = DropDownList3.Items.Count + 1;
DropDownList3.DataBind();
SqlCommand com1 = new SqlCommand("SELECT DISTINCT City FROM DrInfo ", con);
SqlDataAdapter da1 = new SqlDataAdapter(com1);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
DropDownList1.DataSource = dt1;
DropDownList1.DataTextField = "City";
DropDownList1.DataValueField = "City";
DropDownList1.SelectedIndex = DropDownList1.Items.Count + 1;
DropDownList1.DataBind();
con.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
rd.Load(Server.MapPath("MojavezReport.rpt"));
rd.SetDatabaseLogon("", "", @".", "DrInfo ,Majores");
rd.SetParameterValue("dname", TextBox1.Text);
rd.SetParameterValue("startdate", TextBox2.Text);
rd.SetParameterValue("dnum", TextBox3.Text);
rd.SetParameterValue("sex", DropDownList4.Text);
rd.SetParameterValue("city", DropDownList1.Text);
rd.SetParameterValue("smarried", DropDownList2.Text);
rd.SetParameterValue("majorename", DropDownList3.Text);
CrystalReportViewer1.ReportSource = rd;
}
protected void Button2_Click(object sender, EventArgs e)
{
rd.PrintOptions.PrinterName = "HP LaserJet M1522n";
rd.PrintToPrinter(1, false, 0, 1);
CrystalReportViewer1.PrintReport();
}