Hello I am in the progress of migrating a MVC application to a SPA with angular. In the past application I was able to pass a Filestream object from the MVC controller back to my page which prompted the user to download the generated excel file. Within
the SPA I am now working with a webapi controller as well as angular, services and controllers. I can pass the reporting object to the api and generate the memory stream from the NPOI assembly but I am stuck on how to pass this back from the webapi to the
client to prompt them to download.
Here is the webapi method I have so far:
public HttpResponseMessage ExportReport([FromBody]DTOs.Report report)
IReportPersistenceManager manager = ContainerConfigurator.Instance.Resolve<IReportPersistenceManager>();
MemoryStream ms = new MemoryStream();
//we have to pass to the NOPI assemble file type as well as file name
//since we only deal with excel for now we will set it but this could be configured later.
long id = report.ReportId;
string mimeType = "application/vnd.ms-excel";
string filename = "unknown";
manager.ExportDataToExcel(id, (name, mime) =>
mimeType = mime;
filename = name;
ms.Position = 0;
var response = new HttpResponseMessage();
response.Content = new ByteArrayContent(ms.ToArray());
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.ms-excel");
return new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest);
Based upon what I have read using HttpResponseMessge looks to be teh right direction but I am stuck on how to get this object once returned to unravel and prompt the user to download the file. I may be way off on the approach but I was wondering if anyone has
used NPOI with Angular or some other similar SPA framework and what was needed to get the download to fire.
I've also posted this question on
I'd really appreciate any guidance or suggestions on an approach