title: How do you stream an Excel 2007 or Word 2007 file using asp.net and c#
body: <p>I'm working on a web app and need to stream various files.  I can do pdfs, images, and older Office documents.  However, when I try to do with 2007 documents, it breaks.  Here is my code:</p>
  
  <pre><code>    Response.Buffer = true;
      Response.Clear();
      Response.ClearContent();
      Response.ClearHeaders();
      switch (FileExtension.ToLower())
      {
          case "pdf":
              Response.ContentType = "application/pdf";
              break;
          case "doc":
              Response.ContentType = "application/msword";
              break;
          case "docx":
              Response.ContentType = "application/vnd.ms-word.document.12";
              break;
          case "xls":
              Response.ContentType = "application/vnd.ms-excel";
              break;
          case "xlsx":
              Response.ContentType = "application/vnd.ms-excel.12";
              break;
          default:
              Response.ContentType = "image/jpeg";
              break;
      }
      Response.BinaryWrite(buffer);
  </code></pre>
  
  <p>The error that I get is:</p>
  
  <pre>
  An invalid character was found in text content. Error processing resource 'http://DomainName/GetFile.aspx...
  
  PK
  </pre>
  
  <p>Any suggestions?</p>