Custom assemblies for the Reporting Services 2005

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;
2: using System.Security.Permissions;
3: using Microsoft.SharePoint;
4:  
5: public class MyNamespace
6: {
7: public class ReportingExtension
8: {
9: public ReportingExtension()
10: {
11: }
12:  
13: public static string HelloWorld()
14: {
15: return "Hello World.";
16: }
17:  
18: [EnvironmentPermission(SecurityAction.Assert, Unrestricted = true)]
19: [Microsoft.SharePoint.Security.SharePointPermission(SecurityAction.Assert, Unrestricted = true)]
20: public static string getSomeListItem(string url, int itemID)
21: {
22: string returnvalue = string.Empty;
23: try
24: {
25: using (SPSite site = new SPSite(url))
26: using (SPWeb web = site.OpenWeb())
27: {
28: // do something
29: returnvalue = "";
30: }
31: }
32: catch (Exception ex)
33: {
34: return ex.ToString();
35: }
36:  
37: return returnvalue;
38: }
39: }
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:

<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="MyNamespace.ReportingExtension"
Description="Code for SSRS">
<IMembershipCondition
class="UrlMembershipCondition"
version="1"
Url="c:\Program Files\Microsoft SQL Server\MSSQL.1\Reporting
Services\ReportServer\bin\MyNamespace.ReportingExtension.dll"
/>

 

Now you are good to go J

1 Comment

kiquenet

Reply

Great, it would very useful any powershell script to modify rssrvpolicy.config. thx

 

Leave a Reply