Custom assemblies for the Reporting Services 2005
Even if the Reporting Services are very powerfull, you might get to the point where you have to extend the building functionality. So why not write your own custom assembly with some additional code?
Create your assembly like this:
1: using System;<br> 2: using System.Security.Permissions;<br> 3: using Microsoft.SharePoint;<br> 4: <br> 5: public class MyNamespace<br> 6: {<br> 7: public class ReportingExtension<br> 8: {<br> 9: public ReportingExtension()<br> 10: {<br> 11: }<br> 12: <br> 13: public static string HelloWorld()<br> 14: {<br> 15: return "Hello World.";<br> 16: }<br> 17: <br> 18: [EnvironmentPermission(SecurityAction.Assert, Unrestricted = true)]<br> 19: [Microsoft.SharePoint.Security.SharePointPermission(SecurityAction.Assert, Unrestricted = true)]<br> 20: public static string getSomeListItem(string url, int itemID)<br> 21: {<br> 22: string returnvalue = string.Empty;<br> 23: try<br> 24: {<br> 25: using (SPSite site = new SPSite(url))<br> 26: using (SPWeb web = site.OpenWeb())<br> 27: {<br> 28: // do something<br> 29: returnvalue = "";<br> 30: }<br> 31: }<br> 32: catch (Exception ex)<br> 33: {<br> 34: return ex.ToString();<br> 35: }<br> 36: <br> 37: return returnvalue;<br> 38: }<br> 39: }<br> 40: }
Put this line into your AssemblyInfo.cs:
[assembly: AllowPartiallyTrustedCallers]
and sign your assembly with a strong name (see here for details).
Next you have to reference your assembly in your Reporting project in the Report Properties:
You can then use your code like this:
**=MyNamespace.ReportingExtension.getSomeListItem(“http://site/web”, 5)
**
Before you can use your custom assembly, you have to deploy it to the following paths:
- Report Designer C:\Program Files\Microsoft SQL Server\80\Tools\Report Designer
- Reporting Server C:\Program Files\Microsoft SQL Server\MSSQL.1\Reporting Services\ReportServer\bin
And register it in the rssrvpolicy.config file:
<span style="font-family:Courier New;font-size:10pt"><CodeGroup<br /> <span style="color:blue">class</span>=<span style="color:#a31515">"UnionCodeGroup"<br /></span> version=<span style="color:#a31515">"1"<br /></span> PermissionSetName=<span style="color:#a31515">"FullTrust"<br /></span> Name=<span style="color:#a31515">"MyNamespace.ReportingExtension"<br /></span> Description=<span style="color:#a31515">"Code for SSRS"</span>><br /> <IMembershipCondition<br /> <span style="color:blue">class</span>=<span style="color:#a31515">"UrlMembershipCondition"<br /></span> version=<span style="color:#a31515">"1"<br /></span> Url=<span style="color:#a31515">"c:\Program Files\Microsoft SQL Server\MSSQL.1\Reporting <br />Services\ReportServer\bin\MyNamespace.ReportingExtension.dll"<br /></span> /><br /> </span>
Now you are good to go J