protected void ExportDataSet(DataSet ds) { ExportUtility exp = new ExportUtility(); string relativePathFilename = string.Empty; string absoluteFilename = string.Empty; try { FileNamingUtility.GetCsvFileName(Page.Session, ref absoluteFilename, ref relativePathFilename); exp.ExportDataSetToCSV(ds, absoluteFilename); //On the Page load we will open a new window so that the user may choose //to save or open the export. //RegisterExportFileWindow(relativePathFilename); //Commented out the line above, because the window would not work on the First Tier //The First Tier is where the application sits //This will prompt the user to save the file to there own machine. //we know that the file will be opened in Excel. So we replace the DownloadFile(absoluteFilename); } catch (Exception ex) { throw ex; //Allow the exception to flow up the call stack. } }
protected override void Render(System.Web.UI.HtmlTextWriter writer) { BulkSearchReportUtility _reportUtility = new BulkSearchReportUtility(); _reportUtility.dtSearchResults = (DataTable)Session[Global.Parameters.SearchResults]; _reportUtility.BrowserContentType = BrowserExportType.PDF; string fileName = string.Empty; string errorException = string.Empty; string contentType = string.Empty; string extension = string.Empty; string filePath = string.Empty; string pathFilename = string.Empty; try { if (_reportUtility != null) { switch (_reportUtility.BrowserContentType) { case BrowserExportType.Excel: FileNamingUtility.GetExcelFilename(Page.Session, ref absolutePathFilename, ref relativePathFilename); contentType = "application/vnd.ms-excel"; extension = ".xls"; break; case BrowserExportType.PDF: FileNamingUtility.GetAcrobatFilename(Page.Session, ref absolutePathFilename, ref relativePathFilename); contentType = "application/pdf"; extension = ".pdf"; break; case BrowserExportType.CSV: FileNamingUtility.GetCsvFileName(Page.Session, ref absolutePathFilename, ref relativePathFilename); //contentType = "application/vnd.ms-excel"; contentType = "application/csv"; extension = ".csv"; break; default: throw new ApplicationException("Unknown Export Type selected for the the BrowserContentType on the ReportUtility. Unable to run the report"); } filePath = absolutePathFilename.Substring(0, absolutePathFilename.Length - 4); pathFilename = filePath + extension; File.Delete(absolutePathFilename); //Make sure we delete the 0 byte file created when we get the tmp file name absolutePathFilename = filePath; fileName = Path.GetFileName(pathFilename); _reportUtility.ExportReport(absolutePathFilename); //Don't buffer the response stream, we will send it to the client //so ASP.Net does not get mistaken as being deadlocked. Response.Buffer = false; //only need file name in Header Response.AddHeader("Content-Disposition", "inline; filename=\"" + fileName.Replace(@"files\", "") + "\""); Response.ContentType = contentType; //Stream the file. Response.ClearContent(); //Ensure that we send the headers before we send the actual file. Response.WriteFile(absolutePathFilename); Response.Flush(); if (File.Exists(absolutePathFilename)) { File.Delete(absolutePathFilename); } Response.Close(); } } catch (Exception) { base.Render(writer); } finally { _reportUtility.Dispose(); // Session.Remove(stringReportID); } }
protected override void Render(System.Web.UI.HtmlTextWriter writer) { if (Session[Global.Parameters.SubmittedFinal].ToString() == "FINAL") { LessonLearnedUtility _reportUtility = new LessonLearnedUtility(); _reportUtility.LL_ID = Request.QueryString[Global.Parameters.LL_ID].ToString(); _reportUtility.BrowserContentType = BrowserExportType.PDF; string fileName = string.Empty; string errorException = string.Empty; string contentType = string.Empty; string extension = string.Empty; string filePath = string.Empty; string pathFilename = string.Empty; try { if (_reportUtility != null) { switch (_reportUtility.BrowserContentType) { case BrowserExportType.Excel: FileNamingUtility.GetExcelFilename(Page.Session, ref absolutePathFilename, ref relativePathFilename); contentType = "application/vnd.ms-excel"; extension = ".xls"; break; case BrowserExportType.PDF: FileNamingUtility.GetAcrobatFilename(Page.Session, ref absolutePathFilename, ref relativePathFilename); contentType = "application/pdf"; extension = ".pdf"; break; case BrowserExportType.CSV: FileNamingUtility.GetCsvFileName(Page.Session, ref absolutePathFilename, ref relativePathFilename); //contentType = "application/vnd.ms-excel"; contentType = "application/csv"; extension = ".csv"; break; default: throw new ApplicationException("Unknown Export Type selected for the the BrowserContentType on the ReportUtility. Unable to run the report"); } filePath = absolutePathFilename.Substring(0, absolutePathFilename.Length - 4); pathFilename = filePath + extension; File.Delete(absolutePathFilename); //Make sure we delete the 0 byte file created when we get the tmp file name absolutePathFilename = filePath; fileName = Path.GetFileName(pathFilename); _reportUtility.ExportReport(absolutePathFilename); //Don't buffer the response stream, we will send it to the client //so ASP.Net does not get mistaken as being deadlocked. Response.Buffer = false; //only need file name in Header Response.AddHeader("Content-Disposition", "inline; filename=\"" + fileName.Replace(@"files\", "") + "\""); Response.ContentType = contentType; //Stream the file. Response.ClearContent(); //Ensure that we send the headers before we send the actual file. Response.WriteFile(absolutePathFilename); Response.Flush(); if (File.Exists(absolutePathFilename)) { File.Delete(absolutePathFilename); } Response.Close(); } } catch (Exception) { base.Render(writer); } finally { _reportUtility.Dispose(); // Session.Remove(stringReportID); } } else //BASED ON THE REPORT COMING IN. { LLPotentialUtility _reportUtility = new LLPotentialUtility(); _reportUtility.LL_ID = Request.QueryString[Global.Parameters.LL_ID].ToString(); if (Session[Global.Parameters.SubmittedFinal].ToString() == "SUBMITTED") { _reportUtility.ReportFooter = "NOTE: This Lessons Learned input has been submitted to the Lessons Learned Coordinator. It will be searchable when the LL Coordinator has reviewed for completion and quality control."; } if (Session[Global.Parameters.SubmittedFinal].ToString() == "SUBMITTEDSEARCH") { _reportUtility.ReportFooter = "NOTE: This Lesson Learned has been assigned to a Subject Matter Expert, but has not been finalized as a published Lesson Learned."; } _reportUtility.BrowserContentType = BrowserExportType.PDF; string fileName = string.Empty; string errorException = string.Empty; string contentType = string.Empty; string extension = string.Empty; string filePath = string.Empty; string pathFilename = string.Empty; try { if (_reportUtility != null) { switch (_reportUtility.BrowserContentType) { case BrowserExportType.Excel: FileNamingUtility.GetExcelFilename(Page.Session, ref absolutePathFilename, ref relativePathFilename); contentType = "application/vnd.ms-excel"; extension = ".xls"; break; case BrowserExportType.PDF: FileNamingUtility.GetAcrobatFilename(Page.Session, ref absolutePathFilename, ref relativePathFilename); contentType = "application/pdf"; extension = ".pdf"; break; case BrowserExportType.CSV: FileNamingUtility.GetCsvFileName(Page.Session, ref absolutePathFilename, ref relativePathFilename); //contentType = "application/vnd.ms-excel"; contentType = "application/csv"; extension = ".csv"; break; default: throw new ApplicationException("Unknown Export Type selected for the the BrowserContentType on the ReportUtility. Unable to run the report"); } filePath = absolutePathFilename.Substring(0, absolutePathFilename.Length - 4); pathFilename = filePath + extension; File.Delete(absolutePathFilename); //Make sure we delete the 0 byte file created when we get the tmp file name absolutePathFilename = filePath; fileName = Path.GetFileName(pathFilename); _reportUtility.ExportReport(absolutePathFilename); //Don't buffer the response stream, we will send it to the client //so ASP.Net does not get mistaken as being deadlocked. Response.Buffer = false; //only need file name in Header Response.AddHeader("Content-Disposition", "inline; filename=\"" + fileName.Replace(@"files\", "") + "\""); Response.ContentType = contentType; //Stream the file. Response.ClearContent(); //Ensure that we send the headers before we send the actual file. Response.WriteFile(absolutePathFilename); Response.Flush(); if (File.Exists(absolutePathFilename)) { File.Delete(absolutePathFilename); } Response.Close(); } } catch (Exception) { base.Render(writer); } finally { _reportUtility.Dispose(); // Session.Remove(stringReportID); } } }