protected void btnDownload_Click(object sender, EventArgs e) { string contentType = string.Empty; if (ddlFileFormat.SelectedValue.Equals(".pdf")) contentType = "application/pdf"; if (ddlFileFormat.SelectedValue.Equals(".doc")) contentType = "application/ms-word"; if (ddlFileFormat.SelectedValue.Equals(".xls")) contentType = "application/xls"; string empid = Session["Empid"].ToString(); DataTable dsData = new DataTable(); objOldIncBOL.EmpId = Session["Empid"].ToString(); dsData = objOldIncBLL.getdata(objOldIncBOL); string FileName = "File_" + DateTime.Now.ToString("ddMMyyyyhhmmss") + ddlFileFormat.SelectedValue; string extension; string encoding; string mimeType; string[] streams; Warning[] warnings; LocalReport report = new LocalReport(); report.ReportPath = Server.MapPath("~\\UI\\OldRecords\\OldIncrementReport.rdlc"); ReportDataSource rds = new ReportDataSource(); rds.Name = "OldIncrementReport";//This refers to the dataset name in the RDLC file rds.Value = dsData; report.DataSources.Add(rds); Byte[] mybytes = report.Render(ddlFileFormat.SelectedItem.Text, null, out extension, out encoding, out mimeType, out streams, out warnings); //for exporting to PDF var a = mybytes; using (FileStream fs = File.Create(Server.MapPath("~/download/") + FileName)) { fs.Write(mybytes, 0, mybytes.Length); } string fileNames = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ddlFileFormat.SelectedValue; //fileattch.InnerText = ; //string fileName = this.Id.ToString() + extension; //switch (AppConfiguration.DataStoreType) //{ // case DataStoreType.Database: // myFile.Save(); // break; // case DataStoreType.FileSystem: // myFile.Save(Server.MapPath(Path.Combine( // AppConfiguration.UploadsFolder, myFile.FileUrl))); // break; //} Response.ClearHeaders(); Response.ClearContent(); Response.Buffer = true; Response.Clear(); Response.ContentType = contentType; Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName); Response.WriteFile(Server.MapPath("~/download/" + FileName)); Response.BinaryWrite(mybytes); Response.Flush(); Response.Close(); Response.End(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)