title: Download .xlsx file using Response.TransmitFile()
body: <p>I'm working on some code that generates an Excel spreadsheet server-side and then downloads it to the user.  I'm using <a href="http://www.codeplex.com/ExcelPackage" rel="noreferrer">ExcelPackage</a> to generate the file.</p>
  
  <p>The generation is working just fine.  I can open the generated files using Excel 2007 with no issues.  But, I'm having trouble downloading the file with <code>Response.TransmitFile()</code>.</p>
  
  <p>Right now, I have the following code:</p>
  
  <pre><code>//Generate the file using ExcelPackage
  string fileName = generateExcelFile(dataList, "MyReportData");
  
  Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
  Response.ContentType = "application/vnd.xls"
  Response.Charset = "";
  Response.TransmitFile(fileName);
  </code></pre>
  
  <p>When Excel 2007 opens the file downloaded as above, it gives the "file format doesn't match extension" warning.  After clicking past the warning, Excel displays the raw xml contents of the file.</p>
  
  <p>If I change the file extension, like so</p>
  
  <pre><code>Response.AddHeader("content-disposition", "attachment;filename=FileName.xlsx");
  </code></pre>
  
  <p>Excel 2007 gives an "Excel found unreadable content in the file" error, followed by a dialog that offers to locate a converter on the web.  If I click "no" on this dialog, Excel <em>is</em> able to load the data.</p>
  
  <p>I've also experimented with different MIME types, like <code>application/vnd.ms-excel</code> and <code>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</code>, combined with file extensions of .xls and .xlsx.  All combinations result in one of the two behaviors mentioned above.</p>
  
  <p>What is the correct combination of file extension and MIME type to use in this scenario?  What else could cause this failure, other than an improper MIME type or extension?</p>
  
  <p>FYI, this is occurring with Visual Studio's built-in development web server.  I haven't yet tried this with IIS.</p>