In SQL Server Reporting Services 2016, how can I right-justify a municipal logo image loaded from the database into an image item on the report? I plan to use a calculated expression for the image element's Padding.Left
attribute to position the image. Each client (municipality) has a different (single) image to be shown on their reports, and they should line up with the right-hand margin of the report in each case.
I already have working code to get the size of the loaded image (based on this, this, this).
How can I get the width of the image element on the report layout to complete the calculation? Some solutions say to use a report parameter or a custom property as a workaround, but I really really want to get the design size of the actual image element from the report itself (and make it client-proof!)
I've already tried the following:
The expression:
=ReportItems!LogoImage.Width
, (whereLogoImage
is the name of the image element). It gives the error:[BC30456] 'Width' is not a member of 'Microsoft.ReportingServices.ReportProcessing.ReportObjectModel.ReportItem'
.Based on docs for the ReportItem .NET class for SSRS 2016, I tried a VB function in the report's Code area:
Public Function GetReportItemWidth(ByVal itemName As String) As Integer
Dim item As ReportItem
item = ReportItems(itemName)
Return item.Width
End Function
...but that gives an error [BC30469] Reference to a non-shared member requires an object reference.
- When I qualify the member names:
Public Function GetReportItemWidth(ByVal itemName As String) As Integer
Dim item As Microsoft.ReportingServices.ReportRendering.ReportItem
item = Me.Report.Renderer.Report.GetReportItem(itemName)
Return item.Width
End Function
...I get error [BC30002] Type 'Microsoft.ReportingServices.ReportRendering.ReportItem' is not defined.
I'm getting deeper and deeper into Planet DotNet without really knowing what I'm doing, so I decided to ask for help from the community. Any help would be greatly appreciated.
- Should I add a reference to
Microsoft.ReportingServices.dll
? It's not inC:\Windows\Microsoft.NET\Framework\v4.0.30319\
like all the other .net assemblies, but several versions of it are in a few other locations on my hard drive. So, which one? - Am I looking at the correct docs, or is there more than one class named
ReportItem
?
Note that this may be similar to this SO question, but the single answer there (with one vote) which says it's not possible, is from 2014, and makes no mention of various things I've already tried, so I thought things may have changed since then. Also, I'm happy to upgrade to Reporting Services 2017 or later, as I see that a lot has changed between SSRS 2016 and SSRS 2017-2022. (e.g. some of the the .NET classes mentioned above no longer exist, from 2017 onwards etc.)