Articles in this section
Category / Section

How to render the drillthrough report in ASP.NET Core application

1 min read

Render Drillthrough report in ASP.NET Core ReportViewer application:

 

In ASP.NET Core platform when loading the local RDL report then we need to pass the stream for ReportModel. But if that report have drillthrough report then we need to pass the Reportserver with dummy URL, username and password to get the stream for reports as shown in below code example.

public partial class HomeController : Controller, IReportController
    {
        private IMemoryCache _cache;
        private IHostingEnvironment _hostingEnvironment;
 
        public HomeController(IMemoryCache memoryCache, IHostingEnvironment hostingEnvironment)
        {
            _cache = memoryCache;
            _hostingEnvironment = hostingEnvironment;
        }
 
        [HttpPost]
        public object PostReportAction([FromBody] Dictionary<string, object> jsonResult)
        {
            return ReportHelper.ProcessReport(jsonResult, this, this._cache);
        }
 
        [ActionName("GetResource")]
        [AcceptVerbs("GET")]
        public object GetResource(ReportResource resource)
        {
            return ReportHelper.GetResource(resource, this, _cache);
        }
 
        [HttpPost]
        public object PostFormReportAction()
        {
            return ReportHelper.ProcessReport(null, this, this._cache);
        }
 
        public void OnInitReportOptions(ReportViewerOptions reportOption)
        {
            reportOption.ReportModel.ReportServerUrl = "http://<No server>";
            reportOption.ReportModel.ReportServerCredential = new System.Net.NetworkCredential("<no user>", "<no password>");
 
            Reportserver reportserver = new Reportserver(_hostingEnvironment);
            reportOption.ReportModel.ReportingServer = reportserver;
        }
 
        public void OnReportLoaded(ReportViewerOptions reportOption)
        {
           
        }
    }
 
    public class Reportserver : ReportingServer
    {
        private IHostingEnvironment _hostingEnvironment;
 
        public Reportserver(IHostingEnvironment hostingEnvironment)
        {
            _hostingEnvironment = hostingEnvironment;
        }
 
        public override Stream GetReport()
        {
            string basePath = _hostingEnvironment.WebRootPath + "/ReportData/";
            FileStream inputStream = new FileStream(basePath+this.ReportPath+".rdl", FileMode.Open, FileAccess.Read);
            return inputStream;
        }
    }
 

 

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ReportSample_Core1362599618.zip

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied