title: Save a byte array to excel file
body: <p>I get a byte array from ssrs report. Then I want to save it in Excel on server for further processing.
  I am able to export it on client browser but when try to save the file on server it saves. But gives the error while opening &quot;excel can not open the file because the file format or file extension is not valid&quot;.</p>
  <p>code is as follows</p>
  <pre><code>Microsoft.Reporting.WebForms.ReportViewer rview = new Microsoft.Reporting.WebForms.ReportViewer();
  //Web Address of your report server (ex: http://rserver/reportserver)
  
  rview.ServerReport.ReportServerUrl = new Uri(&quot;http://rserver/reportserver&quot;);
  
  rview.ServerReport.ReportPath = &quot;/Report Project2/Comment&quot;;
              
  string mimeType, encoding, extension, deviceInfo;
  string[] streamids;
  Microsoft.Reporting.WebForms.Warning[] warnings;
  string format = &quot;Excel&quot;; //Desired format goes here (PDF, Excel, or Image)
  
  deviceInfo = &quot;&lt;DeviceInfo&gt;&quot; + &quot;&lt;SimplePageHeaders&gt;True&lt;/SimplePageHeaders&gt;&quot; + &quot;&lt;/DeviceInfo&gt;&quot;;
  byte[] bytes = rview.ServerReport.Render(format, deviceInfo, out mimeType, out encoding, out extension, out streamids, out warnings);
  
  try
  {         
      System.IO.FileStream _FileStream = new System.IO.FileStream(Server.MapPath(&quot;output.xlsx&quot;), System.IO.FileMode.Create, System.IO.FileAccess.Write);  
      _FileStream.Write(bytes, 0, bytes.Length);   
      //_FileStream.Close(); 
  }
  catch (Exception _Exception)
  {
      Console.WriteLine(&quot;Exception caught in process: {0}&quot;, _Exception.ToString());
  }
  </code></pre>
  <p>It don't know how to use infor format,deviceInfo etc. that i use with Respose object to save excel on client browser.</p>
  <p>here is how I write to Response object.It works fine gor response object.</p>
  <pre><code>Response.Clear();
  
  if (format == &quot;PDF&quot;)
  {
      Response.ContentType = &quot;application/pdf&quot;;
      Response.AddHeader(&quot;Content-disposition&quot;, &quot;filename=output.pdf&quot;);
  }
  else if (format == &quot;Excel&quot;)
  {
      Response.ContentType = &quot;application/excel&quot;;
      Response.AddHeader(&quot;Content-disposition&quot;, &quot;filename=output.xls&quot;);
  }
  Response.OutputStream.Write(bytes, 0, bytes.Length);
  Response.OutputStream.Flush();
  Response.OutputStream.Close();
  Response.Flush();
  Response.Close();
  </code></pre>