title: Download PDF File in C#
body: <p>In my application I want to give user the option to download a PDF file. In my code, the file gets opened by browser; however, I want the file to be downloaded. Here's my code:</p>
  <p><strong>Controller</strong></p>
  <pre><code>string name = id; //id is the name of the file
  string contentType = &quot;application/pdf&quot;;
  
  var files = objData.GetFiles(); //list of files
  
  
  string filename = (from f in files
                     orderby f.DateEncrypted descending
                     where f.FileName == name
                     select f.FilePath).First(); //gets the location of the file
  
  string FullName = (from f in files
                     where f.FileName == name
                     select f.FileName).First(); //gets the new id in new location to save the file with that name
  
  
  
  //Parameters to File are
  //1. The File Path on the File Server
  //2. The content type MIME type
  //3. The parameter for the file save by the browser
  return File(filename, contentType, FullName);
  </code></pre>
  <p>Here's how I'm using it in dropdown menu.</p>
  <p><strong>View</strong>:</p>
  <pre><code>&lt;li&gt;&lt;a id=&quot;copyURL&quot; href=&quot;@Url.Action(&quot;Download&quot;, &quot;Home&quot;, new { id = item.FileName})&quot;&gt;Download&lt;/a&gt;&lt;/li&gt;
  </code></pre>
  <p>By clicking on &quot;Download&quot;, the file gets opened browser.</p>