Crystal report printing c# web application

Last Reply 14 days ago By dharmendr

Posted 14 days ago

hello sir,

i have reffer your post as below link.

i try to print crystal report but some point i'm not getting kindly help me to solve it.

in below article i have see this below code i'm not getting The Private Customers and .ds how to use. where to use..

in my application i want to print record seperatly like save and print current record. which is being save.

 

https://www.aspforums.net/Threads/129462/Print-all-pages-from-Crystal-Report-on-Button-click-using-C-and-VBNet-in-ASPNet/Answered#Replies

ReportDocument crystalReport = new ReportDocument();
protected void Page_Load(object sender, EventArgs e)
{
    crystalReport.Load(Server.MapPath("~/CrystalReport.rpt"));
    Customers dsCustomers = GetData();
    crystalReport.SetDataSource(dsCustomers);
    CrystalReportViewer1.ReportSource = crystalReport;
    CrystalReportViewer1.DisplayGroupTree = false;
}
 
private Customers GetData()
{
    string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    string query = "SELECT CustomerId,ContactName,City,Country FROM Customers";
    SqlCommand cmd = new SqlCommand(query);
    using (SqlConnection con = new SqlConnection(conString))
    {
        using (SqlDataAdapter sda = new SqlDataAdapter())
        {
            cmd.Connection = con;
            sda.SelectCommand = cmd;
            using (Customers ds = new Customers())
            {
                sda.Fill(ds, "DataTable1");
                return ds;
            }
        }
    }
}
 
protected void Print(object sender, EventArgs e)
{
    // Refresh Report.
    crystalReport.Refresh();
    // Set Paper Orientation.
    crystalReport.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape;
    // Set Paper Size.
    crystalReport.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperA4;
    // CrystalDecisions.Shared.ExportFormatType to change the format i.e. Excel, Word, PDF
    //crystalReport.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, true, "CustomerDetails");
    crystalReport.PrintOptions.PrinterName = GetDefaultPrinter();
    crystalReport.PrintToPrinter(1, true, 0, 0);
}
 
private string GetDefaultPrinter()
{
    PrinterSettings settings = new PrinterSettings();
    foreach (string printer in PrinterSettings.InstalledPrinters)
    {
        settings.PrinterName = printer;
        if (settings.IsDefaultPrinter)
        {
            return printer;
        }
    }
    return string.Empty;
}

 

You are viewing reply posted by: dharmendr 14 days ago.
Posted 14 days ago