protected void btnFile_Click(object sender, EventArgs e) { LinkButton button = (LinkButton)sender; string offerID = string.Empty; if (GXGridView1.SelectedValue != null) { offerID = GXGridView1.SelectedDataKey.Value.ToString(); } else { offerID = GXGridView1SelectedValue.ToString(); } string destinationPath = OfferAttachmens_Directory + @"\" + offerID; string file_path = destinationPath + @"\" + button.Text; FileInfo fi = new FileInfo(file_path); FileStream fs = fi.OpenRead(); byte[] byte_get = new byte[fs.Length]; fs.Read(byte_get, 0, byte_get.Length); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.ClearHeaders(); HttpContext.Current.Response.ContentType = AttachmentController.getMimeType(file_path); HttpContext.Current.Response.Charset = string.Empty; HttpContext.Current.Response.Cache.SetCacheability(System.Web.HttpCacheability.Public); HttpContext.Current.Response.AddHeader("Content-Disposition:", "attachment; filename=" + button.Text); HttpContext.Current.Response.OutputStream.Write(byte_get, 0, byte_get.Length); HttpContext.Current.Response.OutputStream.Flush(); HttpContext.Current.Response.OutputStream.Close(); HttpContext.Current.Response.End(); }