Monday, 2 September 2013

How to add SSRS Reports in ASP.NET


In this article I will explain How to add SSRS Reports in ASP.NET

First you need to develop a SSRS Report, After Open your web application and add new aspx page. Add below lines of code in your web.config file.

Add Report server url, Report server folder, Domain Name, User Name, Password. Follow below steps.

<appSettings>
    <add key="ReportServerUrl" value="http://Localhost/ReportServer" />
    <add key="ReportServerFolder" value="/Newforler" />
    <add key="User" value="Domine Name\ User Name" />
    <add key="Password" value="Password" />
</appSettings>

Below Handler is used for Specifying the reporting server version (Present Used Version is 2008).



<httpHandlers>
<add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
        validate="false" />
 </httpHandlers>

<compilation debug="true" targetFramework="4.0">
      <assemblies>
<add assembly="Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
      </assemblies>
      <buildProviders>
        <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.Common, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      </buildProviders>    
 </compilation>

ASPX Page code:  Add below assembly in your ASPX Page.

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb1" %>

Below is the Report design code.

  <table border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="white">
        <tr>
            <td width="20%">
            </td>
            <td align="center" width="80%" valign="top">
<rsweb1:ReportViewer ID="rptView" runat="server" Visible="false" Width="950px" Height="950px"
                    ShowPrintButton="false" ShowToolBar="false">
                </rsweb1:ReportViewer>
            </td>
            <td width="20%">
            </td>
        </tr>
    </table>

C# Code :

Add below namespaces in aspx.cs page.

using System.Web.Configuration;
using Microsoft.Reporting.WebForms;
using System.Xml;
using System.Web.UI.HtmlControls;
using System.Diagnostics;
using System.Configuration;
using System.Net;

Add below lines of code in Page load or Method.

string userName = WebConfigurationManager.AppSettings["User"];
        string passWord = WebConfigurationManager.AppSettings["Password"];
        this.rptView.ProcessingMode = ProcessingMode.Remote;
        this.rptView.ShowParameterPrompts = false;
        this.rptView.ServerReport.ReportServerUrl = new Uri(WebConfigurationManager.AppSettings["ReportServerUrl"].ToString());
        IReportServerCredentials credentials = new CustomReportCredentials(userName, passWord);
        this.rptView.ServerReport.ReportServerCredentials = credentials;
        this.rptView.ServerReport.ReportPath = WebConfigurationManager.AppSettings["ReportServerFolder"].ToString() + "/ReportName";
        new List<ReportParameter>();
        this.rptView.ServerReport.Refresh();
        this.rptView.Visible = true;

No comments:

Post a Comment