Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
protected void lnkbtnReport_Click(object sender, EventArgs e)
{
LinkButton lnkreport = (LinkButton)sender;
string ID = lnkreport.CommandArgument;





//int ID = objEmp.ID;
ReportDocument rp;
DataSet ds = new DataSet();

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
con.Open();
SqlDataAdapter myadp = new SqlDataAdapter("Employee_Proc_Report", con);
myadp.SelectCommand.CommandType = CommandType.StoredProcedure;

myadp.SelectCommand.Parameters.AddWithValue("@ID", Convert.ToInt32(ID));
myadp.Fill(ds, "TempReport");
rp = new ReportDocument();
DataSet ds1 = new DataSet();
string rptPath = Server.MapPath(@"~\Reports\EmployeeInformationReport.rpt");
rp.Load(rptPath);
rp.SetDataSource(ds.Tables[0]);
SqlDataAdapter adp = new SqlDataAdapter("NeedIdentification_GetReport", con);
adp.SelectCommand.CommandType = CommandType.StoredProcedure;

adp.SelectCommand.Parameters.AddWithValue("@ID", Convert.ToInt32(ID));
adp.Fill(ds1, "TempReport");
rp.OpenSubreport("NonTrainingNeed").SetDataSource(ds1);

rp.SetParameterValue("@ID", Convert.ToInt32(ID), "NonTrainingNeed");
//string Code = ds.Tables[0].Rows[0]["Code"].ToString();
string reportName = "Employee.doc";
string _tempDir = "Reports\\";
string baseDir = AppDomain.CurrentDomain.BaseDirectory;
if (!Directory.Exists(baseDir + "\\" + _tempDir))
Directory.CreateDirectory(baseDir + "\\" + _tempDir);
reportName = baseDir + "\\" + _tempDir + "\\" + reportName;
ExportOptions exp = new ExportOptions();
DiskFileDestinationOptions dsk = new DiskFileDestinationOptions();
dsk.DiskFileName = reportName;
exp = rp.ExportOptions;
exp.DestinationOptions = dsk;
exp.ExportDestinationType = ExportDestinationType.DiskFile;
exp.ExportFormatType = ExportFormatType.WordForWindows;
rp.Export();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
string _tempReportName = System.IO.Path.GetFileName(reportName);
Response.AddHeader("content-disposition", "attachment;filename=" + _tempReportName);
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.WriteFile(reportName);
Response.WriteFile(reportName);
Response.Flush();
Response.Close();

System.IO.File.Delete(reportName);

}
Posted

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