0

I have a controller on server side, and the method

        public ActionResult GetBulletin()
    {

       return File(@"E:\Fileserver\022015.pdf", "application/pdf");
    }

this is triggered when a user clicks on a link on the webpage, the document then is opened in a browser window. the link is

<a href="http://www.domain.com/File/GetBulletin">Download</a>

What i want to do is force the download, I read that we shall use the content disposition header, my question is how to have the server send this header?

        Response.AppendHeader("Content-Disposition", @"attachment; filename=E:\Fileserver\022015.pdf");
        return View() ;

doesn't work of course.thanks.

Yvon Huynh
  • 453
  • 3
  • 16
  • possible duplicate of [How can I present a file for download from an MVC controller?](http://stackoverflow.com/questions/730699/how-can-i-present-a-file-for-download-from-an-mvc-controller) – Misam Sep 29 '15 at 06:29

1 Answers1

1

You should set only file name in your Response.AppendHeader("Content-Disposition", @"attachment; filename=E:\Fileserver\022015.pdf"); statement so it becomes:

Response.AppendHeader("Content-Disposition", @"attachment; filename=022015.pdf");.

Then you can use the File(<file-bytes>, <content-type>) to send the file to the client. In your case this could be done like this:

return File(System.IO.File.ReadAllBytes(@"E:\Fileserver\022015.pdf"), "application/pdf")