I connect to Report Server with an application and run an rdl report in Report Viewer ,
now Question ?
How can I send the report to the printer automatically in Report Viewer?
Thank All of you
private void Form1_Load(object sender, EventArgs e)
{
// Set the processing mode for the ReportViewer to Remote
reportViewer1.ProcessingMode = ProcessingMode.Remote;
reportViewer1.ServerReport.ReportServerUrl = new Uri("http://Server/reportserver");
reportViewer1.ServerReport.ReportPath = #"/Customereport/rms3invoice";
reportViewer1.ServerReport.ReportServerCredentials.SetFormsCredentials(
null, "Admin","admin", null);
ReportParameter reportParameter = new ReportParameter();
reportParameter.Name = "ID";
reportParameter.Values.Add("2");
// reportParameter.Values.Add("3");
reportViewer1.ServerReport.SetParameters(new ReportParameter[] { reportParameter });
this.reportViewer1.RefreshReport();
// reportViewer1.Print += ReportViewer1_Print;
}
Related
I have two report rdlc in my c# application, I want to print both of them when click button.
Here is my code:
private void btnPrint_Click(object sender, EventArgs e)
{
LocalReport report1 = new LocalReport();
report1.ReportPath = Application.StartupPath + "\\Report1.rdlc";
report1.PrintToPrinter();
LocalReport report2 = new LocalReport();
report2.ReportPath = Application.StartupPath + "\\Report2.rdlc";
report2.PrintToPrinter();
}
the code print the first report1.rdlc but the second report2.rdlc not printed. How can I fix this thanks ?
This is my references : https://foxlearn.com/windows-forms/how-to-print-rdlc-report-without-report-viewer-in-csharp-410.html
When i run this on VS it works fine but when i run it on another computer it cant find the RDLC path.
private void button1_Click(object sender, EventArgs e)
{
LocalReport localReport = new LocalReport();
ReportParameterCollection reportParameters = new ReportParameterCollection();
reportParameters.Add(new ReportParameter("Pallet_label", lb_pallet_name.Text));
reportParameters.Add(new ReportParameter("Par_PalNum", LB_Number.Text));
localReport.ReportPath = Application.StartupPath + "\\pallet_label.rdlc";
localReport.SetParameters(reportParameters);
localReport.PrintToPrinter();
}
It will print the report but wont add the report Parameters
private void button1_Click(object sender, EventArgs e)
{
ReportParameterCollection reportParameters = new ReportParameterCollection();
reportParameters.Add(new ReportParameter("Pallet_label", lb_pallet_name.Text));
reportParameters.Add(new ReportParameter("Par_PalNum", LB_Number.Text));
this.rvLabel_pallet.LocalReport.SetParameters(reportParameters);
this.rvLabel_pallet.RefreshReport();
rvLabel_pallet.Visible = true;
LocalReport localReport = new LocalReport();
localReport.ReportPath = rvLabel_pallet + "//pallet_label.rdlc";
//localReport.SetParameters(reportParameters);
this.rvLabel_pallet.RefreshReport();
localReport.PrintToPrinter();
rvLabel_pallet.Visible = false;
I am using VS 2012 Ultimate, SAP Crystal Reports 13_0_13 (latest version).
The problem is that when I click on Crystal Report viewer's "next page" button, it goes on loading and never ends.
I am using the following code.
protected void btn_search_Click(object sender, EventArgs e)
{
Session["ReportDocument"] = null;
loadReport(param1,param2,param3,param4);
}
loadReport function:
private void loadReport(string Param1, string Param2, string Param3, string param4)
{
CrystalReportViewer1.Visible = true;
ReportDocument reportDocument = new ReportDocument();
string reportPath = Server.MapPath(#"~/VacantAndFilledReports/rpt_vacantposts_HR.rpt");
reportDocument.Load(reportPath);
reportDocument.SetDatabaseLogon(ID, pass, serverName, databaseName);
reportDocument.SetParameterValue("#Param1", Param1);
reportDocument.SetParameterValue("#Param2", Param2);
reportDocument.SetParameterValue("#Param3", Param3);
reportDocument.SetParameterValue("Param4", Param4);
CrystalReportViewer1.ReuseParameterValuesOnRefresh = true;
CrystalReportViewer1.AutoDataBind = true;
CrystalReportViewer1.Zoom(88);
CrystalReportViewer1.ReportSource = reportDocument;
Session["ReportDocument"] = reportDocument;
}
I have also place the code in Page_Init:
protected void Page_Init(object sender, EventArgs e)
{
if (Session["ReportDocument"] != null)
{
ReportDocument doc = (ReportDocument)Session["ReportDocument"];
CrystalReportViewer1.ReportSource = doc;
}
}
I have searched a a lot regarding Page Next button, all posts were regarding put code inside Page_Init but tried as above not work for me.
Instead of Page_init place the same piece of code at Page_Load
I have a subreport inside report and i pass a parameter to the sub report tutorUsername.
My code when creating report is this:
reportViewer1.LocalReport.ReportPath = (reportPath + "TestReport.rdlc");
reportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(prcProcessSubReport);
reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("test_DataSet", report));
ReportParameter[] tmpParameters = new ReportParameter[1];
tmpParameters[0] = new ReportParameter("serverNames", serverNamesList, false);
reportViewer1.LocalReport.SetParameters(tmpParameters);
And :
private void prcProcessSubReport(object sender, SubreportProcessingEventArgs e)
{
try
{
string tutorUserName = e.Parameters["tutorusername"].Values[0].ToString();
ReportDataSource rdsTradeDetails = new ReportDataSource("Test_DataSet", report);
e.DataSources.Add(rdsTradeDetails);
//Code End
}
catch (Exception eX)
{
}
}
Now the issue is i do get the parameter valye but its (Fields!Tutor_Username.Value, \"TEST_DataSet\") . I was assuming this way i will get the tutor username for each and i will create /filter datatable with the parameter and add accordingly . Any help? What am i doing wrong is there some other way to get parameter value?
IT was simple had to do like this :
string tutorUserName = (e.Parameters["tutorusername"].Values.First()).ToString();
ReportDataSource rdsTradeDetails = new ReportDataSource("Test_DataSet", report);
e.DataSources.Add(rdsTradeDetails);