I am unsure how to go about exporting my ActiveReports report document to XLS in my asp.net mvc app.
My concept so far is to have a dropdown of export types and a submit button that submits that value to my controller. When I'm on the controller, I regenerate the report and pass it to my Export method. I'm not sure what to have this Export method return. I'm also getting an out of range error on the actual xlsExport.Export method. Below is my Export method. Also to note, reportBase.Report is an ActiveReport3 object.
private ActionResult Export(ReportBase reportBase)
{
Response.ClearContent();
Response.ClearHeaders();
var exportType = Request.Form["exportType"];
switch (exportType)
{
case "RTF":
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=report.rtf");
var rtfExport = new RtfExport();
rtfExport.Export(reportBase.Report.Document, Response.OutputStream);
break;
case "TIFF":
Response.ContentType = "image/tiff";
Response.AddHeader("Content-Disposition", "attachment;filename=report.tif");
var tiffExport = new TiffExport();
var filePath = System.IO.Path.GetTempFileName();
tiffExport.Export(reportBase.Report.Document, filePath);
var fileStream = System.IO.File.Open(filePath, System.IO.FileMode.Open);
var bufferLength = (int)fileStream.Length;
var output = new byte[bufferLength];
var bytesRead = fileStream.Read(output, 0, bufferLength);
Response.OutputStream.Write(output, 0, bytesRead);
System.IO.File.Delete(filePath);
break;
case "XLS":
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=report.xls");
var xlsExport = new XlsExport();
xlsExport.Export(reportBase.Report.Document, Response.OutputStream);
break;
}
Response.Flush();
Response.End();
return View("Display", reportBase);
}