Working with Reporting Services Using Microsoft Sharepoint
page 2 of 3
by Ameet Phadnis
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 47085/ 34

Creating Your Own Reporting Services Web Part

So you are ready to create your own web part because the Reporting Services web part does not allow you to pass default parameters and hide the toolbar. Before we start getting into the code, I would like to explain what is happening behind the scenes when your web part gets displayed.

How does the report get displayed after all? To explain this we will have to first look into how the reports are displayed in Reporting Services. Open the above report in Reporting Services using the Report Manager. After entering the parameters your report should open up as follows.

Place your mouse pointer anywhere in the section of the toolbar with the print button on it, right-click on it, and click view source. When looking at view source you will see some JavaScript with variables set to some URLs. If you look at the dmRepUrl and renderingUrl variables you will notice that the report URL is being pointed to where you have actually stored those reports. The URL on my machine displays as follows.

http://computername/ReportServer?%2fSampleReports%
2fEmployee+Sales+Summary&ReportMonth=12&ReportYear=2003&EmpID=20&rs%
3aFormat=HTML4.0&rs%3aCommand=Render&rc%3aArea=Report&rc%
3aLinkTarget=_top&rc%3aJavaScript=True&rc%3aToolbar=True&rc%
3aReplacementRoot=http%3a%2f%2flocalhost%2fReports%2fPages%
2fReport.aspx%3fServerUrl%3d

 

In my case it points to computername/ReportServer. Reportserver is the place where all my reports are stored. If you look at the string after computername/ReportServer you will notice that after the “?,” you have the “SampleReports/Employee Sales Summary” passed in the querystring. In the above example you will see ReportMonth=12, ReportYear=2003, and EmpID=20 passed in as parameters. So basically, SQL Reporting Services is creating the URL as soon as you set the parameters and when you are ready to render the reports.

Now the question arises: how do you show this report in a web part? That’s where you actually use an IFrame tag to display the report. Now if you switch back to your SharePoint Portal, open the page that displays the Report, and then view the source. Search for the IFrame tag. For the above report you will see it as below.

Source for the IFrame Tag from the SharePoint Page

<IFrame id="fmViewerg_16456605_2905_4a52_98b0_6f9802039e12" 
name="fmViewerg_16456605_2905_4a52_98b0_6f9802039e12" 
src="http://localhost/Reports/Pages/Report.aspx?ItemPath=%
2fSampleReports%2fEmployee+Sales+Summary&amp;
ViewMode=WebPart&amp;StyleSheet=Full" width="100%" height="100%" 
frameborder="0" scrolling="auto"></IFrame>

 

In the above example the code is actually using the Report Manager’s URL to display this report. You might have also noticed that it does not display the parameters because the report is being rendered inside the IFrame. If you click inside the web part and then do a view source you will find the actual URL similar to the one covered in the Reporting Services URL section above.

I will show you how you could use the actual Reporting Server’s URL to display the report.

 

Options to Display the Reports

There are actually two different options to display the report by passing default parameters. Based on the above explanation you might have guessed that you could use the page viewer web part. You are right; you can use it.

Page Viewer web part: You can drop a Page Viewer and add the following URL to its Link property.

Report URL to Display the Report

 

http://localhost/ReportServer?/SampleReports/Employee Sales Summary
&rs:Command=Render&EmpID=20&ReportYear=2003&ReportMonth=12&rc:toolbar=False

 

The above URL will display the report as follows.

With the above you do expect the user to know the exact syntax to enter it in the Properties Window.

The second option is creating your own web part. The easiest way to create your own web part is to convert the Report Viewer Web Control application provided with SQL Reporting Services. If you have installed SQL Reporting Services with the default options you can find the Report Viewer application under

C:\Program Files\Microsoft SQL Server\MSSQL\Reporting Services\Samples\Applications\ReportViewer folder.

Follow these steps to create your own Report Viewer web part:

  1. Open Visual Studio.NET.
  2. Click on File New Project.
  3. Under Visual Basic Projects you should see an entry for Web Part Library. If you have not installed Web Part Library templates you can download and install it from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_sp2003_ta/html/sharepoint_webparttemplates.asp. I strongly recommend downloading these templates and using it for creating new web parts.
  4. Click on Web Part Library and give it a suitable name. I named mine as APRSReportViewer.
  5. Once you create this project, the following files should be added to your Project.
    1. WebPart1.dwp. Rename this file;I renamed it APReportViewer.dwp.
    2. WebPart1.VB. Rename this file too. I renamed it APReportViewer.vb.
    3. AssemblyInfo.vb
    4. Manifest.xml
  6. Replace all the instances of WebPart1 with APReportViewer in code.
  7. Add new Project to the solution using Add Project -> New Project and selecting Cab Project under Setup and Deployment Projects.
  8. On the newly added Cab Project. Right Click and Select Add->Project Output.
  9. Select Primary Output and Content Files from the available list of Add Project Output list.
  10. Click Ok. Your solution should resemble the one below.
  11. Open the APReportViewer.vb file.
  12. Now we will need four properties for ReportServer, Report Start Path, Report Parameters, and whether to display the Toolbar. The following code creates those properties.

Properties Code    

Private _serverURL as string =””
Private _ reportPath as string =””
Private _ showToolbar1 as string =TruePrivate _properties As New Hashtable
<Browsable(True), Category("General Report Parameters"), DefaultValue
(_defaultText), WebPartStorage(Storage.Personal), FriendlyName("ServerURL"),
Description("Server URL Address")> _
Public Property ServerUrl() As String
  Get
    Return Me._serverUrl
  End Get
  Set(ByVal Value As String)
    Me._serverUrl = Value
  End Set
End Property
 
<Browsable(True), Category("General Report Parameters"), DefaultValue
(_defaultText), WebPartStorage(Storage.Personal), FriendlyName
("ReportPath"), Description("ReportPath Property")> _
Public Property ReportPath() As String
  Get
    Return Me._reportPath
  End Get
  Set(ByVal Value As String)
    Me._reportPath = Value
  End Set
End Property
 
<Browsable(True), Category("General Report Parameters"), DefaultValue
(_defaultText), WebPartStorage(Storage.Personal), FriendlyName("Toolbar"), 
Description("Toolbar1 Property")> _
Public Property Toolbar1() As String
  Get
    Return Me._showToolbar1
  End Get
  Set(ByVal Value As String)
    Me._showToolbar1 = Value
  End Set
End Property
 
<Browsable(True), Category("General Report Parameters"), DefaultValue
(_defaultText), WebPartStorage(Storage.Personal), FriendlyName("Report 
Parameters"), Description("Toolbar1 Property")> _
Public Property ReportParameters() As String
  Get
    Return Me._reportParameters
  End Get
  Set(ByVal Value As String)
    Me._reportParameters = Value
  End Set
End Property

In the above code we have declared the _Properties parameter to store all the parameter/ properties information and then use it while creating the URL.

Now we define a method to set the parameters or store the parameters information in the properties variable.

Method for Setting Parameters

Private Sub SetParameter(ByVal name As String, ByVal value As String)
  Try
  'Remove if value is null or empty. Value is null of the property grid value
  'is null or empty. Empty or null removes the property from the Hashtable.
  If value Is Nothing Or value = String.Empty Then
    Me._properties.Remove(name)
  Else
    If Me._properties.ContainsKey(name) Then
      'Change if key exists
      Me._properties(name) = value
    Else
      'Add if key does not exist
      Me._properties.Add(name, value)
    End If
  End If
  'Build a new url string
  Me.BuildUrlString()
  'Catch and handle a more specific exception in a propduction application.
  Catch ex As Exception
    'Sample throws the exception to the client
    Throw ex
  End Try
End Sub 'SetParameter

We also need a method to get all the parameters information in the URL.

Method for Creating Server Access Specific String

Private Function EmumProperties(ByVal properties As Hashtable) As String
  Dim paramsString As String = String.Empty
  'Enumerate properties and create report server specific string.
  Dim customPropEnumerator As IDictionaryEnumerator = properties.GetEnumerator()
  While customPropEnumerator.MoveNext()
    paramsString += "&" + CStr(customPropEnumerator.Key) + "=" + _
      CStr(customPropEnumerator.Value)
  End While
  Return paramsString
End Function 'EmumProperties

We need to build another method to create a complete URL for the report.

Method to Build the URL String

Public Function BuildUrlString() As String
  Me._url = Me._serverUrl + "?" + Me._reportPath + "&rs:Command=Render" + _
    Me.EmumProperties(Me._properties)
  Return Me._url
End Function 'BuildUrlString

We also need to create another method to pass the actual report parameters.

Method to Store the Actual Report Parameters to Filter the Report

Private Sub PassReportParameters()
  Dim strParameters(), strParameter As String
  Dim strParamValues(), strParamName, strParamValue As String
  strParameters = Me._reportParameters.Split("|")
  For Each strParameter In strParameters
    strParamValues = strParameter.Split("=")
    Me.SetParameter(strParamValues(0), strParamValues(1))
  Next
End Sub

Finally, we come to the RenderWebPart method. This is the method where you will display the report in IFrame.

Render Method

Protected Overrides Sub RenderWebPart(ByVal output As System.Web.UI.HtmlTextWriter)
  Try
    If Me._serverUrl = String.Empty OrElse Me._reportPath = String.Empty Then
      output.Write("<P style=""font-family: Verdana; font-size: 11px"">")
      output.Write("To render a report, enter the ServerUrl and ReportPath.</P>")
    Else
      'Me._serverUrl = Me._serverUrl & "/Pages/Report.aspx?ItemPath="
      'Create IFrame if the user enters ServerUrl and ReportPath
      If Me._showToolbar1.Trim.Length > 0 Then
        Me.SetParameter("rc:toolbar", Me._showToolbar1)
      Else
        Me.SetParameter("rc:toolbar", "Default")
      End If
      If Me._reportParameters.Trim.Length > 0 Then
        Me.PassReportParameters()
      End If
      output.WriteBeginTag("IFrame")
      output.WriteAttribute("src", Me.BuildUrlString)
      output.WriteAttribute("width", "100%")
      output.WriteAttribute("height", "100%")
      output.WriteAttribute("style", "border: 1 solid #C0C0C0")
      output.WriteAttribute("border", "0")
      output.WriteAttribute("frameborder", "0")
      </font>output.Write(HtmlTextWriter.TagRightChar)
      output.WriteEndTag("IFrame")
      output.WriteLine()
    End If
  Catch ex As Exception
    output.Write("<P style=""font-family: Verdana; font-size: 11px"">")
    output.Write("Error Occurred while rendering the report.</P>")
  End Try
End Sub

Now compile the solution, and install the Cab file on to the server by running the following command on your command prompt.

""C:\Program Files\Common Files\Microsoft Shared\web server extensions\60
\BIN\STSADM.exe" -o addwppack -filename "c:\Cab\APRSWebPartCab.CAB""

Based on the above web part, you could pass the following values:
  ServerURL - http://localhost/ReportServer 
  ReportPath - /SampleReports/Employee Sales Summary
  Toolbar – False – To hide the parameters toolbar
  Report Parameters - ReportMonth=12|ReportYear=2003|EmpID=20
  The Report Parameters are passed with | delimiter
  The report web part will look like the one below.


View Entire Article

User Comments

Title: test   
Name: guy
Date: 2012-12-06 11:42:16 AM
Comment:
hello
Title: Problem with Report which has size more then 100KB   
Name: Shalini
Date: 2010-07-26 1:32:34 AM
Comment:
I have experiencing prolem in running RDLs which has size more then 100 kb. If I remove some of column from an rdl to make its size up to 100kb and then upload and run, it works fine.
I am able to upload rdl with size more than 100kb on share point 2010 site. But as I click to run or set data source, it gives error.
Title: Problem With Height Option   
Name: RS
Date: 2010-04-15 5:48:57 PM
Comment:
I'm experiencing the same issue as Arvind. Whenever I set the default height to any value, the web part stops rendering 'Apply' button on the right side with parameters. Any suggestions?
Title: good article   
Name: abhishek
Date: 2010-04-09 6:45:37 AM
Comment:
good,but need more snap shot.
Title: Windward Reports   
Name: David Thielen
Date: 2009-11-11 12:01:44 AM
Comment:
For those looking for an alternative to SRSS, Windward Reports has a great plug-in to SharePoint that turns SharePoint into a great reporting, document generation, and dashboard server.
Title: Performance point and Sharepoint reports   
Name: Donovan
Date: 2009-10-26 4:11:22 AM
Comment:
Has anyone ever used Performance Point to create reports for a share poin site?

If anyone knows how please let me know.
Title: Hiding View report button in SSRS   
Name: Anivesh
Date: 2009-08-07 11:17:00 AM
Comment:
Hi All,

I do not want to show view report button of parameter field in SSRS. When I browse my report then every time i select a parameter i have to hit "View Report" button.
Is there any way to hide it...

Thanks in advance.....
Title: Problem With Height Option   
Name: Arvind
Date: 2009-07-29 12:57:21 AM
Comment:
Hi Ameet,
I having a problem of using Report Viewer web part in Sharepoint Integrated Mode.Whenever I set it default height to some value like 800 pixels then it stops rendering 'Apply' button which comes by default on right side with parameters.
I even created a customized report viewer webpart using defaul report viewer as i have requirement of fetching the rdl file path from URL.In that case also 'Apply' button goes missing. Can you please help in this case .
Your help will be highly appreciated

Tx
Title: Have u came across date problems ?   
Name: Anoop Tripathi
Date: 2009-07-27 9:57:10 AM
Comment:
Hi,
i am developing reports using SSRS and displaying them on MS CRM sharepoint portal. But i have came across date problem.
the problem is that everything seems fine in report manager but gives error on sharepoint portal (the date related fields that is).
Thanks
Title: good article   
Name: Neeraj
Date: 2009-03-09 8:52:23 AM
Comment:
thanks for such a good article..
Title: the report is setup and running under a general account.   
Name: Desa
Date: 2009-01-27 12:07:04 AM
Comment:
Hi Ameet
What if the report is setup and running under a general account.

How can i pass the credential onto the reporting server via an URL link or webpart?
Thanks,
Desa
Title: How to generate canned report in Sharepoint   
Name: Bala
Date: 2008-03-13 7:39:14 AM
Comment:
I need to generate the canned reports in MOSS 2007.If anybody knows please give the steps.

Thanks
Title: link with Sharepoint List   
Name: Bistesh
Date: 2008-03-04 7:46:48 AM
Comment:
Hi,
finally I got to link with the SP List items and web service with reporting viewer controls . We have to use the custom dataset to bind,.
Thanks
Title: What Edition of MOSS   
Name: Imad Mansour
Date: 2008-02-29 8:27:21 AM
Comment:
Excellent article.

just would like to know what edition of MOSS do we need to use reporting services EE or SE ???
Title: How to link with Sharepoint List   
Name: bistesh
Date: 2008-01-28 4:23:16 AM
Comment:
Hi, Can you plz tell me that how to link the rdl file with the sharepoint list item so that I have to fetch the data from SP list and display in the report
Title: Images showing correctly for me   
Name: Brendan
Date: 2008-01-09 11:49:22 AM
Comment:
I am not having any problems seeing the images.
Title: Images are not dispplaying properly   
Name: ramesh
Date: 2008-01-09 5:44:36 AM
Comment:
Thanks for this good article.But at the same time pls find that the Images are not dispplaying properly(Images not found). Pls upload the images into proper folder. These are not displaying.
Title: beginner   
Name: anne
Date: 2007-08-15 9:02:44 PM
Comment:
can u please tell me where i can view the Report Viewer and report explorer? i cant find them

thnx a bunch
Title: Beginner   
Name: max
Date: 2007-07-05 12:21:54 AM
Comment:
Hi, i'm a beginner to RS and MOSS. Thanks very much for giving me a resolution for my problem. I had the same problem with connecting Explorer to Viewer. Setting the trust level to WSS_Medium solved the problem. Thanks a lot. Another question would be: when I try to set up RS/MOSS integrated mode rather than native mode, it gives me an error that it can't create a new database for Integration mode even though I am an admin on the box and have full rights on the MOSS server. Any ideas? I draw blank and no resources on the internet or Microsoft site. Thanks.
Title: how to use report viewer on sharepoint   
Name: Joe
Date: 2007-06-28 2:34:07 AM
Comment:
Hi, I'm confused about how to display report in sharepoints. The problem is report manager is appears on report viewer web parts. my question is how to display report on sharepoints without report manager?
Title: Mr   
Name: VIral Shah
Date: 2007-03-22 7:59:55 PM
Comment:
Hi, This is a very good artical, but can you help me with one question which will be really appreciated. I have added one text box on my report, can user enter the text during runtime and can get print of that. I need to do it. Can you Please Help me out. THank you. My Email Address Is: viruchi2002@yahoo.com
Title: Where is the information entered on the ServerURL stored?   
Name: Tim Toennies
Date: 2007-02-06 12:46:32 PM
Comment:
Do you know where this value is stored? Is it in SharePoint's Config database or some other file? I need to know because I want to change the setting for about 90 WebParts and I would rather not have to open each of them individually. Thanks very much for your help.
Title: RE: Having same issue as Gilles   
Name: Mike Knuth
Date: 2007-01-08 9:25:33 AM
Comment:
Ameet:

You were correct. WSS_Minimal, doesn't seem to allow those Web Parts to connect up in MOSS. Modifying the web.config to change the trust level to WSS_Medium, took care of the issue.

Thank you.
Title: RE: Having same issue as Gilles   
Name: Mike Knuth
Date: 2007-01-03 6:31:37 PM
Comment:
I installed the RSWebParts in the GAC. I thought they ran with full trust by default if they were in the GAC? Is there some other setting I missed?
Title: Having same issue as Gilles   
Name: Ameet
Date: 2007-01-03 4:17:50 PM
Comment:
Did you try adjusting the trust level in your Web.Config file? Most probably that should fix it.
Title: Good Info: Having same issue as Gilles   
Name: Mike Knuth
Date: 2007-01-03 3:43:15 PM
Comment:
Nice article. We used some of the information to create our own Web Parts to use on a dashboard. Thanks for the jumpstart!

Gilles:

Did you ever get your issue with connecting the Report Explorer and Viewer parts (in MOSS) squared away? I ran into the same thing this morning. You can put the viewer and explorer web parts on the same page and they work just fine. When you try to connect the viewer with the explorer, it blows up.

If you look in the Event Log, you might see something like: Request for the permission of type 'Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' failed.

If you have any info, please post back. Thanks.
Title: Excellent Article   
Name: Gilles Urena
Date: 2006-12-19 5:40:16 PM
Comment:
Great article. I have implemented on a MOSS platform and found out the connection b/w the explorer and the viewer is not working. Each web part is working individually.
Title: Excellent   
Name: Anwar
Date: 2006-11-30 1:28:26 AM
Comment:
Ameet, Thanks for sharing your knowledge. This is indeed a wonderful article. I was quite confused since long, but this article has helped me in understanding and getting the things correctly. Thanks a lot buddy!
Title: Good article but ..   
Name: Patrick
Date: 2006-10-25 1:53:57 AM
Comment:
I tried to follow the the exercise but its confusing when you mentioned :-
the best way is to web part is to convert the Report Viewer Web Control application provided with SQL Reporting Services. I have the ReportViewer application.But its not really clear in your article how to use it.How to convert that application to a web part? Some properties etc are missing with what you have on your article compared to whats in the application report viewer.
Title: Good article but ..   
Name: Patrick
Date: 2006-10-25 1:52:20 AM
Comment:
I tried moving whats in the report viewer app to a WEB PART LIBRARY BUT I GET ERROR
"One of the properties of the Web Part has an incorrect format. Windows SharePoint Services cannot deserialize the Web Part. Check the format of the properties and try again."
Title: Problem with direct connection   
Name: A
Date: 2006-10-23 1:50:22 PM
Comment:
Check the Web Parts which you created. Check if you are using the right web parts (Consumer or Provider)
Title: Problem with direct connection   
Name: Simone
Date: 2006-10-23 11:13:40 AM
Comment:
Hi, I made the excercise but, the direct connection between Report Explorer and Report Viewer doesn't work! What is the possible problem?
Title: GoBack to Parent in WebPart   
Name: Hugo Eduardo Perez
Date: 2006-10-17 11:47:05 AM
Comment:
It is a very good article. I need add GoBack to Parent button or control in WebPart in child reports for Go Back to de Parent Report, simmilar to Preview in report Designer. The Standar Button is Hide (in Internet Explorer).
It´s possible Go Gack to parent in WebPart Sharepoint ReportViewer?!!

Thanks, and if you could e-mail me any information you think helpfull @: hugoeperezm@yahoo.com.
Thank You very much!
Title: Displaying the three parameters in a single row   
Name: Ameet
Date: 2006-10-11 5:06:40 PM
Comment:
You need to write your own parameter control for that.

Thanks,

Ameet
Title: Displaying the three parameters in a single row   
Name: Athmaram
Date: 2006-10-07 6:50:29 AM
Comment:
Hi, I have an issue regarding displaying the 3 parameters in single row. by default sql reporting services display only 2 parameters in a row. Kindly help me how to display 3 parameters in a single row in report manager.(ie during preview or generating the report). Kindly send the suggestions to athmaramp@gmail.com
Title: Bug in Jump to Url   
Name: Mugnaboa
Date: 2006-09-15 9:10:49 AM
Comment:
I open my report in a iframe. I use a "jump to url" link in the report with the javascript code, i need to jump in a new window. It's not work!
Title: I couldn't use this in SPA2007   
Name: K K
Date: 2006-09-04 5:14:39 AM
Comment:
I was able to use the settings mentioned in SPS2003 but not in 2007. I get the error while connecting explorer and viewer. Error message is Request for the permission of type 'Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' failed
Title: Excellent   
Name: Aron Roberto
Date: 2006-08-29 9:37:36 PM
Comment:
It is a very good article, I have to convert intranet to sharepoint, and I have no idea where to begin, even though your article was help full. can you please refer to me books or sites or any think you believe that can help me accomplish this project. Thanks, and if you could e-mail me any information you think helpfull @: bn_aron@yahoo.com.
Thank You very much!
Title: I could'nt finish the example I had some errors   
Name: Heis
Date: 2006-07-10 2:15:06 PM
Comment:
I made the exercise but, I had some error at the moment to ocmpile, this variable reportParameters what kind of type is it? In fact i did it in C#






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-17 8:31:09 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search