Let's say you have an assembly fully qualified as ReportUtils, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
with your utility methods.
It has 2 classes:
- public static class
ReportUtils.Foo
with a public method string GetValue()
- public class
Bar
with a parameterless constructor and a public property Id
.
Visual Studio 2008
Report -> Report Properties -> References
- References section.
RDL xml
add
<CodeModules>
<CodeModule>ReportUtils, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</CodeModule>
</CodeModules>
under the Report
element.
You can also add instances of your classes that will get auto-constructed when you report is loaded:
Visual Studio 2008
same menu as before - Classes section.
RDL xml
add
<Classes>
<Class>
<ClassName>ReportUtils.Bar</ClassName>
<InstanceName>barInstance</InstanceName>
</Class>
</Classes>
under the Report
element.
You can use your static utility method like this:
<Value>=ReportUtils.Foo.GetValue()</Value>
You can use your class instance like this:
<Value>=Code.barInstance.Id</Value>
You have to add your assembly as trusted to the LocalReport
instance you are using:
localReport.AddTrustedCodeModuleInCurrentAppDomain("ReportUtils, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
You may have to copy your ReportUtils
assembly to your VS2008\Common7\IDE\PrivateAssemblies directory so you can design your reports in Visual Studio's report designer without errors.
I have used this recently so this should be all the necessary steps to achieve your goal.