How to download pdf file in mvc2

153 Views Asked by At

I have a "Gallery" folder with one pdf file

I view the pdf file using an object, then I need to download that pdf by clicking a "Click here to download the pdf file" link

please help me,

I view the pdf file using an object, after that below I have "Click here to download the pdf file " when I click that link I want able to download the pdf

here's the code I have so far:

 public ActionResult downloadpdf()
 {
     using (var client = new WebClient())
     {
         var buffer = client.DownloadData("~/Gallery/NewsBulletin.pdf");
         return File(buffer, "application/pdf", "mypdffile.pdf");
     }
 }
1

There are 1 best solutions below

0
Serega On
public ActionResult DownloadPdf()
{
   return File("mypdffile.pdf", "application/pdf", 
       Server.MapPath("~/Gallery/NewsBulletin.pdf"));
}

If file isn't in site directory, you can still specify the full path in controller action, i.e.

public ActionResult DownloadPdf()
{
   return File("mypdffile.pdf", "application/pdf", 
       "C:\\VerySecretFile.pdf");
}