Open an web api generated file in new tab

Francisco Rubio Delgado 1 Reputation point
2020-12-14T11:14:07.77+00:00

Hi all!
I coded a Web Api wich generates and returns a pdf file, in Blazor Server web app.
It works, I can write the controller url and the pdf file shows correcty.
But I want to open it when the user clics a button. I think it wouldn't be hard, but I can't manage it.

My Controller:

 [HttpGet]
        [Route("InformeClientes")]
        public IActionResult ClientesReport()
        {
            DataTable dt = [function to generate report data]
            var path = [path to the report definicion - rdlc]

            [open report]
            [fill report with data]
            var result = localReport.Execute(RenderType.Pdf, 1, parameters, "");

            return File(result.MainStream, System.Net.Mime.MediaTypeNames.Application.Octet, "Informe.pdf");
        }

If I call it this way:

void Exportar()
{          
    var fichero = clienteHttp.GetAsync("api/Clientes/InformeClientes");    
}

The variable get filled, and no erros occurs, so I think it works (and if I write the api url in the browser the pdf is shown) How can I show the file in new tab programmatically?

Thanks.

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,158 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,386 questions
{count} votes