public void DownloadPdfBtnClicked(object sender, EventArgs e) { try { string EmmaPDFPathFolder = (System.Configuration.ConfigurationManager.AppSettings["EmmaPDFPathFolder"]); long routeId = 0; var directory = Directory.GetParent(HttpRuntime.AppDomainAppPath); var parentDir = directory.Parent; if (ddlMenuType.SelectedItem.Text == "All" || ddlFlightFrom.SelectedItem.Text == "All" || ddlFlightTo.SelectedItem.Text == "All") { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "CheckPDFOnFTP", "AlertCheckPDFOnFTP();", true); return; } int menuTypeId = -1; if (ddlMenuType.SelectedValue != "All") { menuTypeId = Convert.ToInt32(ddlMenuType.SelectedValue); } if (ddlFlightFrom.SelectedItem.Text != "All" && ddlFlightTo.SelectedItem.Text != "All") { routeId = _routeManagement.GetRouteId(ddlFlightFrom.SelectedItem.Text, ddlFlightTo.SelectedItem.Text); } var fileNames = _menuProcessor.GeneratePdfFileNameForDownload(Convert.ToInt64(ddlCycle.SelectedValue), Convert.ToInt32(ddlClass.SelectedValue), menuTypeId, routeId); if (fileNames.Count == 0 && (ddlMenuType.SelectedValue != "All" && ddlFlightFrom.SelectedItem.Text != "All" && ddlFlightTo.SelectedItem.Text != "All")) { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "NoPDFOnFTP", "AlertNoPDFOnFTP();", true); } else { if (fileNames.Count == 1) { FileInfo pdffile = new FileInfo(EmmaPDFPathFolder + @"\MENU PDFS\" + fileNames[0]); if (pdffile.Exists) { string fname = pdffile.Name; fname = fname.Replace(" ", "_"); Response.ClearContent(); Response.Buffer = true; Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", fname)); Response.ContentType = "application/ms-excel"; Response.TransmitFile(pdffile.FullName); Response.End(); } } else { Response.AddHeader("Content-Disposition", "attachment; filename=" + "MenuPDF" + ".zip"); Response.ContentType = "application/zip"; using (var zipStream = new ZipOutputStream(Response.OutputStream)) { foreach (string filePath in fileNames) { var path = EmmaPDFPathFolder + @"\MENU PDFS\" + filePath; byte[] fileBytes = System.IO.File.ReadAllBytes(path); var fileEntry = new ZipEntry(Path.GetFileName(path)) { Size = fileBytes.Length }; zipStream.PutNextEntry(fileEntry); zipStream.Write(fileBytes, 0, fileBytes.Length); } zipStream.Flush(); zipStream.Close(); } } } } catch (Exception ex) { //write to Elma ErrorSignal.FromCurrentContext().Raise(ex); } }