Wednesday, November 16, 2005

SQL Reporting Services: URL Generation Code

Here is a little method I made to build the query string to pass to reporting services.
-showToolbar shows or hides the toolbar with paging, printing, exporting, etc.
-showParameters shows or hides the entry fields that allow a user to change what values the report is generated from
-properties is a name value collection of parameters that you can supply to the report to generate it instead of the user having to type them into the boxes if ShowParameters is on.

Private Function BuildPropertyString(showToolbar as boolean, showParameters as boolean, properties as NameValueCollection) As String
If _properties Is Nothing Then Return ""
Dim sb As New System.Text.StringBuilder

if ShowToolbar then sb.Append("&rc:Toolbar=true")
if ShowParameters then sb.Append("&rc:Parameters=false&")
For Each key As String In properties.Keys
sb.Remove(sb.Length - 1, 1) 'remove the trailing &
Return sb.ToString
End Function

NOTE: this function will exit if no properties are passed to it.
Also it would have been beter of me to rename properties to parameters now that I look at it :)


Post a Comment

<< Home