title: How to programmatically run and export to HTML a ReportViewer
body: <p>This question has two parts. Part 1: How can I programmatically run a reportviewer and part 2: How to programmatically export to html a reportviewer.</p>
  
  <p>Part 1: the .rdl is hosted on a remote server and I need to run this report as if the user had clicked "view results"but in a programmatic way. I'm giving it the right report url, path and parameters, but I seems to be missing something cause when I export it, the results are 0 which means it didn't run. I'm pretty sure I'm missing something but I don't know what it is.</p>
  
  <p>Part 2: I'm running on VS12. I had read you couldn't export to HTML in VS10, but in VS12 you can, but it comes out all wrong. This report has a few tables with color padded cells. The cells aren't colored even though the data is align in a table format. I got it working on a pdf format, but data is null cause of part 1. I'd would prefer it to be on an html format cause I plan to place this export on an email's body.</p>
  
  <p>This is what I got so far:</p>
  
  <pre><code>report.ServerReport.ReportPath = reportPath;
  
  //Assign parameters
  var parameters = new List&lt;ReportParameter&gt;();
  
              parameters.Add(new ReportParameter("Param1", param1));
  
              parameters.Add(new ReportParameter("Param2", param2));
  
              //Execute report
              report.ServerReport.SetParameters(parameters.ToArray());
  
              string mimeType,
                  encoding,
                  fileNameExtension;
  
              Warning[] warnings;
  
              string[] streamIds;
  
              //Export report
              byte[] exportBytes = report.ServerReport.Render("HTML4.0", null, out mimeType, out encoding,
                  out fileNameExtension, out streamIds, out warnings);
  
               //For pdf format
               //HttpContext.Current.Response.Buffer = true;
               //HttpContext.Current.Response.Clear();
               //HttpContext.Current.Response.ContentType = mimeType;
               //HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=ExportedReport." + fileNameExtension);
               //HttpContext.Current.Response.BinaryWrite(exportBytes);
               //HttpContext.Current.Response.Flush();
               //HttpContext.Current.Response.End();
  
              var exportHtml = System.Text.Encoding.UTF8.GetString(exportBytes);
  </code></pre>
  
  <p>If it's not to much to ask, please add some explanation to your answer. I'm still new to reporting and I would like to understand why it's not working. </p>