Tuesday, May 3, 2011

Using ReportViewer control in SharePoint

Scenario:
We plan to use Report Viewer control in SharePoint for some reporting needs.

Solution:
It was a small challenge to make it work with SharePoint. Here's my experience ( error / resolutions )

Error 1 : The Report Viewer Web Control HTTP Handler has not been registered in the application's web.config file. Add <add verb="*" path="Reserved.ReportViewerWebControl.axd" type = "Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> to the system.web/httpHandlers section of the web.config file.

Error was self explanatory. I was suppose to register new HTTPHandler to my web.config. Here's how it will look like after adding it.

<httpHandlers>
<remove verb="GET,HEAD,POST" path="*" />
<add verb="GET,HEAD,POST" path="*" type="Microsoft.SharePoint.ApplicationRuntime.SPHttpHandler, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
<add verb="OPTIONS,PROPFIND,PUT,LOCK,UNLOCK,MOVE,COPY,GETLIB,PROPPATCH,MKCOL,DELETE,(GETSOURCE),(HEADSOURCE),(POSTSOURCE)" path="*" type="Microsoft.SharePoint.ApplicationRuntime.SPHttpHandler, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
<add verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add verb="*" path="Reserved.ReportViewerWebControl.axd" type = "Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</httpHandlers>
I refreshed the screen and got

Error 2 : The type 'Microsoft.SharePoint.Portal.Analytics.UI.ReportViewerMessages, Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' does not implement IReportViewerMessages

This was tricky but with some google helped me. I noticed 'ReportViewerMessages' under AppSettings. I removed it and error was gone.

I refreshed the screen and got

Error 3: Session state is disabled in web.config for SharePoint. The Report Viewer control requires that session state be enabled in local mode.

This was able straight forward. I enabledSessionState = true.
 <pages enableSessionState="true" enableViewState="true" enableViewStateMac="true" validateRequest="false" pageParserFilterType="Microsoft.SharePoint.ApplicationRuntime.SPPageParserFilter, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" asyncTimeout="7">
Small update for SP2010
My good friend Clayton tried this on SP2010 but still got error related to session state not enable.

Running following command helped him.
Enable-SPSessionStateService –DefaultProvision 
One more thing > Don't make these changes to web.config directly but go for something which we have done. We have used a custom application page in layouts to host all the reports. Also we created a local web.config there and updated all these settings in there to reduce the impact to least.

2 comments:

Anonymous,  February 16, 2012 at 8:03 AM  

The Report Viewer Web Control HTTP Handler has not been registered in the application's web.config file. Add to the system.web/httpHandlers section of the web.config file.

Sara Mohamed,  October 8, 2012 at 3:15 AM  

Thanks, It is a Very good article and I need to add a small thing if the report viewer still does not work please remove this "pageParserFilterType"