Asp .Net Core Download Report from SSRS

不问归期 提交于 2021-01-05 10:46:19

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/56492683/asp-net-core-download-report-from-ssrs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!