Tuesday, April 20, 2010

SharePoint 2010: Configure RDLC report with ReportViewer

I have worked with SharePoint 2010 beta 2 and found the RDL(C) report is not configured automatically.  To run a sample report I did the following things. To make sure the configuration works for reporting just put a reportviewer control inside a webpart/page and try to access the page. First of all make sure you have intalled “Microsoft Report Viewer 2010 Redistributable Package”. You can download Microsoft Report Viewer 2010 Redistributable Package from http://www.microsoft.com/downloads/details.aspx?FamilyID=a941c6b2-64dd-4d03-9ca7-4017a0d164fd&displaylang=en.

Here are the steps to configure the SharePoint for report:

1. First find the following line in AppSettings and comment it out as shown below:

  <!--<add key="ReportViewerMessages" value="Microsoft.SharePoint.Portal.Analytics.UI.ReportViewerMessages, Microsoft.SharePoint.Portal, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />-->

2. By default session is disabled in SharePoint. Enable it by ensuring an entry like below inside <system.web>.

<sessionState mode="InProc" timeout="60" />

3. Enable session at page level by setting the enableSessionState to true of <page…..> tag inside system.web.

<pages enableSessionState="true" enableViewState="true" enableViewStateMac="true" validateRequest="false" ……………………=""

4. SharePoint disable the default session module inside the <system.webserver>\modules tag. To enable the module comment out the following line inside <system.webserver>\moudles as shown below:

<!--<remove name="Session" />-->

Now if you try to put a reportviewer control you will find a message like below:

image

If you find the above error then follow the steps 5, 6 and 7:

5. Add the following tag inside system.web\httphandlers section

<add verb="*" path="Reserved.ReportViewerWebControl.axd" type = "Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

6. Add the following line in the system.webserver\handlers

<add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

7. Comment out the following line in the system.WebServer\httphandlers (If Exists)

<!--<add name="ReportViewerWebControl" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />—> 

 

And finally it worked………..

Monday, April 5, 2010

SharePoint 2010: New method added to check if list exists or not

In SharePoint 2007, there was no method to check if a list exists or not, though it was a kind of basic requirement in any public API. The only way to check if list exists or not it as shown below. You needed to apply indexer to Web.Lists collection. If list existed then you would get the list either an exception would be thrown.

SPList myList = null;
try
{
myList = SPContext.Current.Web.Lists["mylist"];
}
catch { }

if(myList!=null)
{
//List exists
}

In SharePoint 2010, a new method TryGetList is added to check list existence. If the list doesn’t exists then the method returns null instead of throwing exception. However TryGetList takes list title but not list ID. It’s logical as if you have list guid then it might be true that you know the list exists (If the list doesn’t exist then how have you got the list id?).

SPList myList = SPContext.Current.Web.Lists.TryGetList('mylist');
if(myList!=null)
{
//List exists
}