title: ASP.NET Excel file download on button click
body: <p>To preface, all of this occurs on a local intranet, which does not at any point need to connect to the internet.</p>
  
  <p>I have a database on which I run a query, after which the user presses a "Download Spreadsheet" button which creates/sends the spreadsheet. The creation of the spreadsheet works fine, but after many attempts I cannot get the file to download. Here's what I've tried:</p>
  
  <ul>
  <li>Modifying the Response/Header objects
  <ul>
  <li>TransmitFile</li>
  <li>WriteFile</li>
  <li>BinaryStream</li>
  <li>Redirect</li>
  </ul></li>
  <li>Javascript Redirect
  <ul>
  <li>Response.Write(javascript code)</li>
  </ul></li>
  </ul>
  
  <p>In most cases, the result is that the excel file is created, but no redirect/download occurs. In the case of Response.Redirect(), if it's a website it works great, but if it's a redirect to a file:///, then it throws a thread exception but no more detail.</p>
  
  <p>I suspect it has to do with the lifecycle of an ASP.NET document, but I'm afraid I am not experienced enough with ASP.NET to be able to know for sure.</p>