Wednesday, 14 November 2012

View SSRS Report and passing parameters into it using report viewer ASP.NET

Dear All
As we like to make every thing is dynamic in this post i will show how to view a SSRS report published in the report server  using ASP.NET and also passing to it a parameters as the code below

        If Page.IsPostBack = False Then


                ReportViewer1.ServerReport.ReportServerCredentials = New ReportCredentials
                ReportViewer1.ShowCredentialPrompts = False
                ReportViewer1.ServerReport.ReportServerCredentials = New ReportCredentials()
                ReportViewer1.ProcessingMode = ProcessingMode.Remote

                Dim sReportName As String = "/budget/Budget_Actual"
                ReportViewer1.ServerReport.ReportServerUrl = New System.Uri("http://sv-ssrs01/Reportserver")
                ReportViewer1.ServerReport.ReportPath = sReportName

                ReportViewer1.ShowParameterPrompts = False

                ReportViewer1.ServerReport.SetParameters(New ReportParameter("BudgetYear", "2010"))
                ReportViewer1.ServerReport.SetParameters(New ReportParameter("BudgetYear2", "2012"))
                ReportViewer1.ServerReport.SetParameters(New ReportParameter("DepartmentID", "IT"))



            Catch ex As Exception

            End Try


Public Class ReportCredentials
    Implements IReportServerCredentials
    Private _Username As String
    Private _Password As String
    Private _Domain As String

    Public Sub New()
        _Username = ConfigurationManager.AppSettings("ReportServerUserName").ToString
        _Password = ConfigurationManager.AppSettings("ReportServerPassword").ToString
        _Domain = ConfigurationManager.AppSettings("DOMAIN").ToString
    End Sub

    Public ReadOnly Property ImpersonationUser() As WindowsIdentity Implements IReportServerCredentials.ImpersonationUser
            Return Nothing
        End Get
    End Property

    Public ReadOnly Property NetworkCredentials() As System.Net.ICredentials Implements IReportServerCredentials.NetworkCredentials
            Return New Net.NetworkCredential(_Username, _Password, _Domain)
        End Get
    End Property

    Public Function GetFormsCredentials(ByRef authCookie As System.Net.Cookie, ByRef userName As String, ByRef password As String, ByRef authority As String) As Boolean Implements IReportServerCredentials.GetFormsCredentials
        userName = _Username
        password = _Password
        authority = _Domain
        Return Nothing
    End Function

End Class

No comments:

Post a Comment