Integreted SSRS reference with .net applications

The easiest way to integrated with .net application is: create an frame or under one content area, when the user click the report menu item and then reference to the SSRS url.


Pass parameters: &SID=98
Hide parameters: &rc:Parameters=false
Hiding toolbar: &rc:Toolbar=false
Report Format (Opening Excel or Acrobat by default): &rs:Format=Excel / &rs:Format=PDF

The other way is to reference the SSRS web service directly, in this way, we can use .net code to control the report generation and be able to generate the final report format directly (PDF, excel etc.)

Dim ssrsservername As String
ssrsservername = ConfigurationManager.AppSettings("SSRS_Server")

Dim ping As Ping = New Ping()
Dim pingreply As PingReply = ping.Send(ssrsservername)
If pingreply.Status = IPStatus.Success Then
    Dim rs As New ReportExecutionService()
    rs.Credentials = System.Net.CredentialCache.DefaultCredentials

    ' Render arguments
    Dim result As Byte() = Nothing
    Dim reportPath As String = "/myreportfolder/myreport"
    'Dim format As String = Server.UrlEncode(ddlFormat.SelectedValue)
    Dim format As String = "PDF"
    Dim historyID As String = Nothing
    Dim devInfo As String = "<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"

    ' Prepare report parameter.
    Dim parameters As ParameterValue() = New ParameterValue(1) {}
    parameters(0) = New ParameterValue()

    parameters(0) = New ParameterValue()
    parameters(0).Name = "ID"
    parameters(0).Value = infoID.Trim

    Dim credentials As DataSourceCredentials() = Nothing
    Dim showHideToggle As String = Nothing
    Dim encoding As String = Nothing
    Dim mimeType As String = Nothing
    Dim extension As String = Nothing
    Dim warnings As Warning() = Nothing
    Dim reportHistoryParameters As ParameterValue() = Nothing
    Dim streamIDs As String() = Nothing

    Dim execInfo As New ExecutionInfo()
    Dim execHeader As New ExecutionHeader()

    rs.ExecutionHeaderValue = execHeader
    execInfo = rs.LoadReport(reportPath, historyID)
    rs.SetExecutionParameters(parameters, "en-us")
    Dim SessionId As [String] = rs.ExecutionHeaderValue.ExecutionID
	result = rs.Render(format, devInfo, extension, encoding, mimeType, warnings, streamIDs)
	execInfo = rs.GetExecutionInfo()
	Debug.Print(String.Format("Execution date and time: {0}", execInfo.ExecutionDateTime))
    Catch soapError As SoapException
    End Try

	Dim stream As FileStream = File.Create(pdfpath, result.Length)
	stream.Write(result, 0, result.Length)
    Catch IOError As Exception
    End Try

End If

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s