lblFile.Text = Issue.FileName; if (lblFile.Text != "") { trAttachedFile.Visible = true; lbtnDownload.PostBackUrl = "~/Download.aspx?file=" + lblFile.Text; } else { trAttachedFile.Visible = false; }
protected void Page_Load(object sender, EventArgs e) { if (!string.IsNullOrEmpty(Request.QueryString["file"])) { DownloadID = Request.QueryString["file"]; if (StartDownload() == true) { lblMessage.Text = "Your download should start shortly"; } else { lblMessage.Text = "Download File does not exist"; } } private bool StartDownload() { if (DownloadID != "") { string downloadPath = WebConfigurationManager.AppSettings["SubPic"].ToString() + DownloadID; FileInfo downloadFile = new FileInfo(downloadPath); if (downloadFile.Exists) { Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=" + downloadFile.Name); Response.AddHeader("Content-Length", downloadFile.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.WriteFile(downloadFile.FullName); Response.End(); return true; } } return false; }
<tr runat="server" id="trAttachedFile"> <td> <asp:Label runat="server" Text="File Attachment:" /> </td> <td colspan="2"> <asp:Label runat="server" ID="lblFile" /> <asp:LinkButton runat="server" Text="Download" ID="lbtnDownload" CssClass="lbtnDownload" /> </td> <td> </td> </tr>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)