0

when I click on it my file doesn't open properly enter image description here

string filePath = (sender as LinkButton).CommandArgument;
            Response.ContentType = ContentType;

          //  Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(filePath));
            Response.AddHeader("Content-Disposition", "inline; filename"+Path.GetFileName(filePath)+".pdf");

            Response.WriteFile(filePath);
            Response.End();
        }
Vishvadeep singh
  • 1,624
  • 1
  • 19
  • 31
  • try this: Content-Type: application/pdf Content-Disposition: attachment; filename="filename.pdf" – Vishvadeep singh Nov 22 '17 at 08:51
  • There is a similar question here https://stackoverflow.com/questions/15458477/response-writefile-not-working-asp-net-mvc-4-5 – lyz Nov 22 '17 at 15:30

1 Answers1

0

You can try this code to get your work done,

string pdfPath = Server.MapPath("~/SomePDFFile.pdf");
WebClient client = new WebClient();
Byte[] buffer = client.DownloadData(pdfPath);
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", buffer.Length.ToString());
Response.BinaryWrite(buffer);
A_Sk
  • 4,532
  • 3
  • 27
  • 51