0

I want to replace >>>>Response.WriteFile(FilePath);<<<< with a code that will download the pdf file.

LinkButton lnk = (LinkButton)sender;
if (lnk != null)
{
    Response.ContentType = "Application/pdf";
    string entry = lnk.CommandName;
    string FilePath = _FilePath + GetFolderName(entry) + lnk.CommandArgument.ToString();
    Response.WriteFile(FilePath); 
    Response.End();
}

thanks in advance!!! :D

David De Chavez
  • 57
  • 1
  • 15

3 Answers3

1

Try this header application/octet-stream instead of application/pdf

Chris Li
  • 3,715
  • 3
  • 29
  • 31
1

you need to append header as well

Response.ContentType = "Application/pdf"; 
Response.AppendHeader("Content-Disposition", "attachment; filename=YourFileName.pdf"); 
Response.TransmitFile(Server.MapPath("~/Files/YourFileName.pdf")); 
Response.Flush() 
Response.End();
Kiarash
  • 1,701
  • 2
  • 16
  • 20
  • 1
    should do here is another example http://stackoverflow.com/questions/1869987/asp-net-response-binarywrite-file-download-being-block-with-ssl – Kiarash May 15 '13 at 03:45
  • i have another question pls. what directory will i put to this Response.TransmitFile(Server.MapPath("~/Files/YourFileName.pdf")); – David De Chavez May 15 '13 at 03:54
  • 1
    In my example I assumed that your file is located in Files folders located in the app roots and it named YourFileName.pdf ~ means root so if your pdf is located in the root you just say "~/YourFileName.pdf" and so on – Kiarash May 15 '13 at 03:57
0
FileInfo fi = new FileInfo(@Request.PhysicalApplicationPath + File_Name);//
long sz = fi.Length;
Response.ClearContent();
Response.ContentType = MimeType(Path.GetExtension(File_Name));
Response.AddHeader("Content-Disposition", string.Format("attachment; filename = {0}", System.IO.Path.GetFileName(File_Name)));
Response.AddHeader("Content-Length", sz.ToString("F0"));
Response.TransmitFile(File_Name);
Response.End();
karthi
  • 450
  • 3
  • 14