protected void LinkButton1_Click(object sender, EventArgs e) { try { var linkBtn = sender as LinkButton; string[] fileNames = linkBtn.Text.Split('\\'); //string tempfile = linkBtn.Text.Replace('\\', '/'); string tempFileName = fileNames[fileNames.Length - 1]; /*Response.ContentType = "image/jpeg"; Response.AppendHeader("Content-Disposition", "attachment; filename=" + tempFileName); Response.TransmitFile(linkBtn.Text); Response.End();*/ Response.Buffer = true; Response.Clear(); Response.AppendHeader("Content-Type", "application/jpg"); Response.AppendHeader("Content-disposition", "attachment; filename=" + tempFileName + ".pdf"); FileStream sourceFile = new FileStream(linkBtn.Text, FileMode.Open); long FileSize; FileSize = sourceFile.Length; byte[] getContent = new byte[(int)FileSize]; sourceFile.Read(getContent, 0, (int)sourceFile.Length); sourceFile.Close(); Response.BinaryWrite(getContent); Response.Flush(); Response.Close(); } catch (SoapException sx) { msg = sx.Message.Replace("'", ""); msg = msg.Replace("\n", ""); lblErrorMessage.Text = msg; } catch (Exception ex) { msg = ex.Message.Replace("'", ""); msg = msg.Replace("\n", ""); lblErrorMessage.Text = msg; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)