Click here to Skip to main content
15,849,163 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
C#
protected void BtnApprove_Click(object sender, EventArgs e)
        {
            ReportDocument cryPrntRpt;
            cryPrntRpt = new ReportDocument();
            cryPrntRpt.Load(Server.MapPath("~\\CrReports\\CrPrintReport.rpt"));
            cryPrntRpt.SetDatabaseLogon("UNM", "PWD", @"SRVNM", "MYDB");

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


            try
            {
                ExportOptions CrExportOptions;
                DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
                PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
                cryPrntRpt.PrintToPrinter(1, false, 0, 0);
                CrDiskFileDestinationOptions.DiskFileName = "D:\\PDF\\" + Regno.ToString() + ".PDF";
                CrExportOptions = cryPrntRpt.ExportOptions;
                {
                    CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                    CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
                    CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
                    CrExportOptions.FormatOptions = CrFormatTypeOptions;
                }
                cryPrntRpt.Export();
            }
            catch (Exception ex)
            {
                //Message(ex.ToString());
            }
            con.Close();
    }



Iam not getting any print from my printer (VS2010,windows 8.1,SAP Crystal reports for VS2010). Please Help Me.
Posted
Updated 2-Jan-15 10:18am
v4

1 solution

I don't see any code segment which is binding data to crystal report.You have to bind your data to report DataSource.Here is a good tutorial you to follow

Step by Step Creation of Crystal Report using its Features Group, Graph, Cross-Tab and Sub Report[^]
 
Share this answer
 
Comments
Member 10989312 3-Jan-15 1:13am    
Report is showing on pageload and it is also exporting to pdf, after displaying the report on button click event (Approve Button) i want to take printout.


protected void Page_Load(object sender, EventArgs e)
{


ConnectionInfo myConnectionInfo = new ConnectionInfo();
myConnectionInfo.ServerName = "SRVNM";
myConnectionInfo.DatabaseName = "MYDB";
myConnectionInfo.UserID = "UNM";
myConnectionInfo.Password = "PWD";
setDBLOGONforREPORT(myConnectionInfo);
}

private void setDBLOGONforREPORT(ConnectionInfo myconnectioninfo)
{
TableLogOnInfos mytableloginfos = new TableLogOnInfos();
mytableloginfos = CrystalReportViewer1.LogOnInfo;
foreach (TableLogOnInfo myTableLogOnInfo in mytableloginfos)
{
myTableLogOnInfo.ConnectionInfo = myconnectioninfo;
}
//ReportDocument cryPrntRpt;
cryPrntRpt = new ReportDocument();
cryPrntRpt.Load(Server.MapPath("~\\CrReports\\CrPrintReport.rpt"));
cryPrntRpt.SetDatabaseLogon("UNM", "PWD", @"SRVNM", "MYDB");



}
Dilan Shaminda 3-Jan-15 1:19am    
You can use PrintToPrinter method

ex:

System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument();
rptDoc.PrintOptions.PrinterName = printDocument.PrinterSettings.PrinterName;
rptDoc.PrintToPrinter(1, true, 0, 0);
Member 10989312 3-Jan-15 1:38am    
i tried with the above code, problem not sloved...i am not getting any error also...
Dilan Shaminda 3-Jan-15 1:48am    
what is the error you are getting?put printing code after you export it to pdf
Member 10989312 3-Jan-15 2:03am    
i am not getting any error... in the button click event after print code i am exporting to pdf, and the pdf file is storing on d:\pdf folder successfully.



protected void BtnApprove_Click(object sender, EventArgs e)
{
ReportDocument cryPrntRpt;
cryPrntRpt = new ReportDocument();
cryPrntRpt.Load(Server.MapPath("~\\CrReports\\CrPrintReport.rpt"));
cryPrntRpt.SetDatabaseLogon("UNM", "PWD", @"SRVNM", "MYDB");

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


try
{
ExportOptions CrExportOptions;
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
cryPrntRpt.PrintToPrinter(1, false, 0, 0);
CrDiskFileDestinationOptions.DiskFileName = "D:\\PDF\\" + Regno.ToString() + ".PDF";
CrExportOptions = cryPrntRpt.ExportOptions;
{
CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
CrExportOptions.FormatOptions = CrFormatTypeOptions;
}
cryPrntRpt.Export();
}
catch (Exception ex)
{
//Message(ex.ToString());
}
con.Close();
}


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