protected void lnkFile_Click(object sender, EventArgs e) { LinkButton lnk = sender as LinkButton; char[] token = { '/' }; int orgID = int.Parse(lnk.CommandArgument.Split(token)[0]); int tippaniID = int.Parse(lnk.CommandArgument.Split(token)[1]); int tippaniProcessID = int.Parse(lnk.CommandArgument.Split(token)[2]); int attachmentID = int.Parse(lnk.CommandArgument.Split(token)[3]); try { byte[] bytes = BLLGeneralTippaniAttachment.GetAttachedFile(orgID, tippaniID, tippaniProcessID, attachmentID); string mimeType = "application/octet-stream"; string ext = System.IO.Path.GetExtension(lnk.Text); Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext); if (regKey != null && regKey.GetValue("Content Type") != null) { mimeType = regKey.GetValue("Content Type").ToString(); } Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=" + lnk.Text); Response.AddHeader("Content-Length", bytes.Length.ToString()); Response.ContentType = mimeType; Response.BinaryWrite(bytes); Response.Flush(); Response.Close(); Response.End(); GC.Collect(); GC.SuppressFinalize(bytes); bytes = null; } catch (Exception ex) { this.lblStatusMessage.Text = ex.Message; this.programmaticModalPopup.Show(); } }
public void LoadTippaniAttachmentDetail(int orgID, int tippaniID) { ATTGeneralTippaniAttachment info = new ATTGeneralTippaniAttachment(); info.OrgID = orgID; info.TippaniID = tippaniID; try { List <ATTGeneralTippaniAttachment> lst = BLLGeneralTippaniAttachment.GetAttachment(info, tippaniID.ToString() + ", "); this.grdAttachment.DataSource = lst; this.grdAttachment.DataBind(); Session["Tippani_Attachment"] = lst; } catch (Exception ex) { this.lblStatusMessage.Text = ex.Message; this.programmaticModalPopup.Show(); } }