title: Returning an MVC FileContentResult to download .pdf file from
body: <p>Hi I've search around for this quite a bit but I didn't find a situation that really resembled mine..hope I didn't miss a duplicate somewhere</p>
  
  <p>The Goal: Return a file from a UNC share to the client as a download/open option. </p>
  
  <p>Info: The share is located on a different server than the one hosting the web site. When a corresponding folder name on the menu is clicked, I am able to successfully read from the share (I return the files as a JSON result) and in Jquery I then append list items for each file found in the folder and make the list item ID's the filename. This works great.</p>
  
  <p>When these appended list items are clicked on I pass their ID's (which are the filename, like "thefile.pdf") to the following controller which returns a FileContentResult. </p>
  
  <p><code>files[0].ToString()</code> below is similar to "\server\folder\"</p>
  
  <pre><code>public ActionResult OpenTheFile(string id)
  
  {
  
  List&lt;string&gt; files = new List&lt;string&gt;();
  
  files.AddRange(Directory.GetFiles(LNFiles.ThePath, id, SearchOption.AllDirectories));
  
  Response.AppendHeader("Content-Disposition", "attachment; filename=" + id + ";");
  
  return File(files[0].ToString(), System.Net.Mime.MediaTypeNames.Application.Pdf, id);
  
  }
  </code></pre>
  
  <p>And yes the obligatory "it works on my local machine". When deployed to the IIS 7.5 server and I click on the list item I get this YSOD error:</p>
  
  <blockquote>
    <p>The handle is invalid. (Exception from
    HRESULT: 0x80070006 (E_HANDLE))</p>
  </blockquote>
  
  <p>I'm impersonating a user with rights to the file share...I'm at a loss, i was thinking something with encoding or screwed up rights? I've tried using a virtual dir instead but alas same issue.</p>