public static string ExportPDF(decimal SubCon, string FromDate, string ToDate, string FileName, string SessionID, string option) { ReportViewer ReportViewer1 = new ReportViewer(); ReportViewer1.LocalReport.EnableExternalImages = true; dsWeldingATableAdapters.VIEW_WELDING_REPORTTableAdapter weld_rep_psjv = new VIEW_WELDING_REPORTTableAdapter(); ReportViewer1.LocalReport.ReportPath = "WeldingInspec\\Reports\\DailyWeldingReport_KOC.rdlc"; switch (option) { case "individual": break; case "entrydate": ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("dsWeldingA_VIEW_WELDING_REPORT", weld_rep_psjv.GetDataByEntry(DateTime.Parse(FromDate), DateTime.Parse(ToDate), SubCon) as DataTable)); break; case "welddate": ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("dsWeldingA_VIEW_WELDING_REPORT", weld_rep_psjv.GetDataByWeld(DateTime.Parse(FromDate), DateTime.Parse(ToDate), SubCon) as DataTable)); break; //case "inspdate": // ReportViewer1.LocalReport.ReportPath = "WeldingInspec\\Reports\\DailyWeldingReport_KOC.rdlc"; // ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("dsWeldingA_VIEW_WELDING_REPORT", weld_rep_psjv.GetDataByInsp(DateTime.Parse(FromDate), DateTime.Parse(ToDate), SubCon) as DataTable)); // break; } Warning[] warnings; string[] streamIds; string mimeType = string.Empty; string encoding = string.Empty; string extension = "pdf"; FileStream stream;// = new FileStream(); try { byte[] bytes = ReportViewer1.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings); if (!Directory.Exists(System.Web.HttpContext.Current.Server.MapPath("~/WeldingInspec/Temp/" + SessionID))) { Directory.CreateDirectory(System.Web.HttpContext.Current.Server.MapPath("~/WeldingInspec/Temp/" + SessionID)); } stream = new FileStream(System.Web.HttpContext.Current.Server.MapPath("~/WeldingInspec/Temp/" + SessionID + "/" + FileName + ".pdf"), FileMode.Create, FileAccess.ReadWrite); stream.Write(bytes, 0, bytes.Length); stream.Close(); stream.Dispose(); } finally { //stream.Close(); //stream.Dispose(); } return("0"); }
//REP,ENTRYDATE1,ENTRYDATE2,WELDDATE1,WELDDATE2,INSPDATE1,INSPDATE2,ISOLIST,,FITUP_DATE1,FITUP_DATE2,FILMNAME,REPORT_TYPE public string ExportPDF1(string Arg1, string Arg2, string Arg3, string Arg4, string Arg5, string Arg6, string Arg7, string Arg8, string Arg9, string Arg10, string filename, string report_type) { ReportViewer ReportViewer1 = new ReportViewer(); ReportViewer1.LocalReport.EnableExternalImages = true; VIEW_WELDING_REPORTTableAdapter weld_rep_psjv = new VIEW_WELDING_REPORTTableAdapter(); //ReportViewer1.LocalReport.ReportPath = "WeldingInspec\\Reports\\DailyWeldingReport_KOC.rdlc"; if (report_type == "fitupentry" || report_type == "fitupdate") { ReportViewer1.LocalReport.ReportPath = "WeldingInspec\\Reports\\DailyFitupReport_STD.rdlc"; } else { ReportViewer1.LocalReport.ReportPath = "WeldingInspec\\Reports\\DailyWeldingReport_STD.rdlc"; } // ReportViewer1.LocalReport.ReportPath = "REPORTS\\DESIGN\\Dly_Weld_Insp_Rep.rdlc"; if (!string.IsNullOrEmpty(Arg1)) { ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource( "dsWeldingA_VIEW_WELDING_REPORT", weld_rep_psjv.GetData(Arg1) as DataTable)); } else if (Arg2 != null && Arg3 != null) { ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource( "dsWeldingA_VIEW_WELDING_REPORT", weld_rep_psjv.GetDataByEntry(DateTime.Parse(Arg2), DateTime.Parse(Arg3), decimal.Parse(cboSubcon.SelectedValue)) as DataTable)); } else if (Arg4 != null && Arg5 != null) { ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource( "dsWeldingA_VIEW_WELDING_REPORT", weld_rep_psjv.GetDataByWeld(DateTime.Parse(Arg4), DateTime.Parse(Arg5), decimal.Parse(cboSubcon.SelectedValue)) as DataTable)); } else if (Arg6 != null && Arg7 != null) { ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource( "dsWeldingA_VIEW_WELDING_REPORT", weld_rep_psjv.GetDataByFitupEntry(DateTime.Parse(Arg6), DateTime.Parse(Arg7), decimal.Parse(cboSubcon.SelectedValue)) as DataTable)); } else if (Arg8 != null) { string query = "Select *From VIEW_WELDING_REPORT WHERE ISO_ID IN (" + Arg8 + ") AND SUB_CON_ID=" + decimal.Parse(cboSubcon.SelectedValue); ///////////////////////////////////////////////////////////////////// string connstr = ConfigurationManager.ConnectionStrings["ipmsConnectionString"].ConnectionString; DataTable dt = new DataTable(); OracleConnection conn = new OracleConnection(connstr); conn.Open(); OracleCommand cmd = new OracleCommand(query); cmd.CommandType = CommandType.Text; cmd.Connection = conn; using (OracleDataAdapter dataAdapter = new OracleDataAdapter(cmd)) { dataAdapter.Fill(dt); } conn.Close(); ///////////////////////////////////////////////////////////////////// ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource( "dsWeldingA_VIEW_WELDING_REPORT", dt)); } else if (Arg9 != null && Arg10 != null) { ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource( "dsWeldingA_VIEW_WELDING_REPORT", weld_rep_psjv.GetDataByFitupDate(DateTime.Parse(Arg9), DateTime.Parse(Arg10), decimal.Parse(cboSubcon.SelectedValue)) as DataTable)); } Warning[] warnings; string[] streamIds; string mimeType = string.Empty; string encoding = string.Empty; string extension = "pdf"; //byte[] bytes = ReportViewer1.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings); byte[] bytes = ReportViewer1.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings); //MemoryStream s = new MemoryStream(bytes); //s.Seek(0, SeekOrigin.Begin); //System.Web.HttpContext.Current.Response.BinaryWrite(bytes); //System.Web.HttpContext.Current.Response.Clear(); System.Web.HttpContext.Current.Response.Buffer = true; System.Web.HttpContext.Current.Response.Clear(); System.Web.HttpContext.Current.Response.ContentType = mimeType; System.Web.HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename= " + filename + "." + extension); //System.Web.HttpContext.Current.Response.OutputStream.Write(bytes, 0, bytes.Length); // create the file Response.BinaryWrite(bytes); //System.Web.HttpContext.Current.Response.Flush(); // download //Context.ApplicationInstance.CompleteRequest(); return("0"); }