title: WebAPI 2 exports Excel,PDF that corupted when deploy on IIS 7/8 but work normally in IIS 10 on my local machine
body: <p>WebAPI 2 exports Excel,PDF that corupted when deploy on IIS 7/8 but work normally in IIS 10 on my local machine. Here is the excel file when I open it <a href="https://i.stack.imgur.com/jKD0T.png" rel="nofollow noreferrer">enter image description here</a></p>
  <p>Here is my code to render excel</p>
  <pre><code>[HttpPost]
      [Route(&quot;api/ThiSinhDuThi/ExportExcel&quot;)]
      public HttpResponseMessage ExportExcel()
      {
  
          string filepath = HttpContext.Current.Server.MapPath(&quot;~/Excel_Template/BieuDSTSDuThi.xls&quot;);
          //FileInfo template = new FileInfo(filepath);
          HSSFWorkbook hssfwb;
          using ( FileStream file = new FileStream(filepath, FileMode.Open, FileAccess.Read) )
          {
              hssfwb = new HSSFWorkbook(file);
              file.Close();
          }
         
          using ( var memoryStream = new MemoryStream() ) //creating memoryStream
          {
              hssfwb.Write(memoryStream);
            
              var response = new HttpResponseMessage(HttpStatusCode.OK)
              {
                  Content = new ByteArrayContent(memoryStream.ToArray())
              };
              
              response.Content.Headers.ContentType = new MediaTypeHeaderValue
                     (&quot;application/vnd.ms-excel&quot;);
              response.Content.Headers.ContentDisposition =
                     new ContentDispositionHeaderValue(&quot;attachment&quot;)
                     {
                         FileName = &quot;DSThiSinhDuThi.xls&quot;
                     };
              
              return response;
          }
          //return stream;
  
  
      }
  </code></pre>