title: How to download file with MVC4/Razor
body: <p>I have a MVC-application. And I want to download a pdf. </p>
  
  <p>This is a part of my view:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;p&gt;
      &lt;span class="label"&gt;Information:&lt;/span&gt;
      @using (Html.BeginForm("DownloadFile")) { &lt;input type="submit" value="Download"/&gt; }
  &lt;/p&gt;
  </code></pre>
  
  <p>And this is a part of my controller:</p>
  
  <pre class="lang-c# prettyprint-override"><code>private string FDir_AppData = "~/App_Data/";
  
  public ActionResult DownloadFile()
  {
      var sDocument = Server.MapPath(FDir_AppData + "MyFile.pdf");
  
      if (!sDocument.StartsWith(FDir_AppData))
      {
          // Ensure that we are serving file only inside the App_Data folder
          // and block requests outside like "../web.config"
          throw new HttpException(403, "Forbidden");
      }
  
      if (!System.IO.File.Exists(sDocument))
      {
          return HttpNotFound();
      }
  
      return File(sDocument, "application/pdf", Server.UrlEncode(sDocument));
  }
  </code></pre>
  
  <p>How can I download the specific file?</p>