Jackal
Jackal

Reputation: 3521

Asp .Net Core Download Report from SSRS

I have been trying hard to get a report from SSRS but seems like it is not supported in .Net Core. So I would like to know if is there a way to just download the report on browser in Asp .Net Core with parameters? All i need is to download it, no need to preview it with report view since there is no compatibility for this.

User clicks a button and parameters are sent through controller or razor page and just need a way to get report and download on browser

Upvotes: 1

Views: 4534

Answers (1)

Osman
Osman

Reputation: 1490

According to microsoft documentation, you need to first generate url according to your ssrs report & parameter as following...

https://servername/ReportServer_THESQLINSTANCE/Pages/ReportViewer.aspx?%2freportfolder%2freport+name+with+spaces&rs:Format=pdf

then pass this url to the following Controller Action....

    public IActionResult GetReportingData(string url)
    {
        try
        {                
            url = url.Replace("\n", "");
            WebRequest request = WebRequest.Create(url);           

            NetworkCredential credentials = new NetworkCredential(@"**UserName*", "***Password***");
            request.Credentials = credentials;

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream stream = response.GetResponseStream();

            return File(stream, "application/pdf");

        }
        catch (Exception ex)
        {
            return BadRequest(ex.Message);
        }
    }

this action will return/download a pdf file as you required.

Upvotes: 2

Related Questions