1
My controller returns two file types: pdf and excel.
return File(stream, "application/pdf");
return File(new MemoryStream(ep.GetAsByteArray()), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", $"Relatorio.xlsx");
When the request can be made by get, I do it as follows:
window.open(urlComParametros, "_blank");
This way a new tab is opened, if the file type is pdf it opens for viewing, and if the type is excel the file is downloaded.
However, now I need to do the request by post. I already did, converting the file to byte[] and then converting to Base64string. So, in the Success of my request I do the following to open the files:
window.open("data:application/pdf;base64," + data, "_blank");
window.open("data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64," + data, "_blank");
That way it works, but there are some problems:
- I couldn’t change the tab title
- I could not change the name of the excel file that is downloaded
- Does not work in IE
How can I resolve these issues? Or is there any better way to return these files?
Dude, the append didn’t work because the pdf opens on that default pdf preview screen of Chrome and apparently it replaces the title for "date:". In the case of excel, where should I set the file name? Because I convert a Filestream into byte[] and then into a Base64 string, but none of these places can change the name. Thanks for your help!
– André Morais Martins
@Andrémoraismartins I updated the answer.
– Leonel Sanches da Silva
Show! Thanks man!
– André Morais Martins