Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?

C#
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();
    }
Posted
Updated 10-Aug-12 17:23pm
v5
Comments
Please post your codes by clicking on "Improve Question" link button.
veusk 10-Aug-12 6:15am    
i posted my codes . please help me

1 solution

Your syntax in that line seems to be ok:
http://msdn.microsoft.com/en-us/library/ms226031%28v=vs.90%29.aspx[^]

HAve you checked that the printer exists:
http://msdn.microsoft.com/en-us/library/ms225960%28v=vs.80%29.aspx[^]

Try nothing instead, then it will use the default printer.

So good luck to you :)
 
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