Friday, December 16, 2011

code for Attach SSRS Report in Asp.Net(VB)

-------------------------------------
>>>setting in web.config file
-------------------------------------
<appSettings>
        <add key="repString" value="ReportServerUrl" />
        <add key="ReportServerUser" value="Userid"/>
        <add key="ReportServerPass" value="Password"/>
        <add key="ReportServerHost" value="ReportServerIP"/>
 </appSettings>
<buildProviders>
    <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.Common, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
   </buildProviders>
<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>
-------------------------------------------------------
code in aspx file
-------------------------------------------------------
>>>register in aspx file
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

>>> take report viewer control in aspx file
<rsweb:ReportViewer ID="MyReportViewer" runat="server"
        Visible="true" Font-Names="Verdana"
                        Font-Size="8pt" Width="100%" Height="400px"
        SizeToReportContent="true" ProcessingMode="Remote" AsyncRendering="true"   
                        ShowPrintButton="True" ShowToolBar="True">
             </rsweb:ReportViewer>
-------------------------------------------------
>>>code in aspx.vb file
-------------------------------------------------
'function start
Try
            Dim reporturl As String
            reporturl = ConfigurationManager.AppSettings("repString").ToString()
            Dim mycred As IReportServerCredentials = New        CustomReportCredentials(ConfigurationManager.AppSettings("ReportServerUser").ToString(), ConfigurationManager.AppSettings("ReportServerPass").ToString(), ConfigurationManager.AppSettings("ReportServerHost").ToString())
            MyReportViewer.ServerReport.ReportServerCredentials = mycred
            MyReportViewer.ServerReport.ReportServerUrl = New Uri(reporturl)
            MyReportViewer.ServerReport.ReportPath = "/langaugereport/org_english"
            MyReportViewer.ShowParameterPrompts = False
            MyReportViewer.ShowCredentialPrompts = False
            MyReportViewer.ServerReport.Refresh()
            MyReportViewer.Visible = True
            Response.ContentType = "text/HTML"
        Catch ex As Exception
            Response.Write(ex.Message)
        End Try
'function end
------------------------------------------
>>>create new class CustomReportCredentials.vb
------------------------------------------
Imports System.Net
Public Class CustomReportCredentials
    Implements Microsoft.Reporting.WebForms.IReportServerCredentials

    ' local variable for network credential
    Private strUserName As String
    Private strPassWord As String
    Private strDomainName As String
    Public Sub New(ByVal UserName As String, ByVal PassWord As String, ByVal DomainName As String)
        strUserName = UserName
        strPassWord = PassWord
        strDomainName = DomainName
    End Sub
    Public ReadOnly Property ImpersonationUser() As System.Security.Principal.WindowsIdentity Implements Microsoft.Reporting.WebForms.IReportServerCredentials.ImpersonationUser
        Get
            ' not use ImpersonationUser
            Return Nothing
        End Get
    End Property
    Public ReadOnly Property NetworkCredentials() As System.Net.ICredentials Implements Microsoft.Reporting.WebForms.IReportServerCredentials.NetworkCredentials
        Get
            ' use NetworkCredentials
            Return New NetworkCredential(strUserName, strPassWord, strDomainName)
        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 Microsoft.Reporting.WebForms.IReportServerCredentials.GetFormsCredentials
        ' not use FormsCredentials unless you have implements a custom autentication.
        authCookie = Nothing
        password = authority = Nothing
        Return False
    End Function
End Class
-----------------------------------------
for more


       





1 comment: