Skip to main content Skip to footer

How to View Reports in Your ASP.NET Webforms Application

ActiveReports.NET has been at the forefront of .NET reporting tools for a long time. As such, we not only offer several report types to satisfy your reporting needs, but we also have report viewer components for practically every .NET platform.

While we have blogs that address our other web-based report viewer components, in this blog, I want to show how to embed the WebViewer control in an ASP.NET Web Forms application.

Create the Application

First, we need to create a basic ASP.NET application. Once that is done, add the GrapeCity.ActiveReports.Web NuGet package to the project by right-clicking the References node and selecting Manage NuGet Packages. 

After successfully adding the NuGet package, add a new Web Form to the page and name it WebViewer.aspx. Open your Global.asax file to add the following code to the Application_Start():

this.UseReporting(settings =>
            {
                settings.UseFileStore(new DirectoryInfo(Server.MapPath("~/Reports")));
                settings.UseCompression = true;
            }
 
);

Adding a Report

In this blog, we will assume that you have existing Section, Page, or RDL reports. If you don't have existing reports, look at this page for walkthroughs on creating your first report with ActiveReports.NET.

Create a folder in the project to store your report files and name it Reports. Add your report files to this folder by right-clicking it and selecting Add→Existing Item...

Add a Report

Adding The WebViewer Control

Open the WebViewer.aspx page to add the WebViewer control by dragging and dropping from Visual Studio Toolbox. Adjust the size if you would like. In the Page_Load event, add the following code to pass a report to the viewer:

protected void Page_Load(object sender, EventArgs e)
        {
            WebViewer1.ReportName = "menu.rdlx";            
        }

Add the HTTP handler to the <configuration> tags in your web.config as follows:

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <add verb="*" path="api/reporting/*" type="System.Web.Handlers.ScriptModule" name="nostaticfile" resourceType="Unspecified" preCondition="integratedMode" />
    </handlers>
</system.webServer>

You are done unless you want to specify a ViewerType. The WebViewer has three different ViewerTypes: HTML (default), Acrobat, and RawHTML. You can specify this in the Page_Load event as discussed above:

HTMLViewer

AcrobatReader

RawHTML

WebViewer1.ViewerType = GrapeCity.ActiveReports.Web.ViewerType.HtmlViewer;

WebViewer1.ViewerType = GrapeCity.ActiveReports.Web.ViewerType.AcrobatReader;

WebViewer1.ViewerType = GrapeCity.ActiveReports.Web.ViewerType.RawHtml;

HTML Viewer Acrobat Reader Raw HTML

To see the complete implementation, download the sample from this link: AR16WebViewerWebForms.zip

Learn more about ActiveReports.NET features by visiting our Online Demos

comments powered by Disqus