Reporting Services is commonly used in an enterprise and Report Manager is one of the most convenient ways to make reports accessible to the users. When using Report Manager, users can export reports to different formats like PDF, XLS and others. When reports are exported to other formats they also include all of the content from the report, but rendered to the format of the report output. There maybe scenarios where you would not want a particular part or component of report to appear in these other report formats. A practical example of this could be that you want to display images when the report is displayed in HTML, but not when the report is exported to a PDF format. In this tip we take a look at a new feature in Reporting Services that allows us to control these items without having to create multiple report versions.
In SQL Server Reporting Services 2008 R2, a new global variable has been introduced - "RenderFormat". This variable can be used in a variety of scenarios including for the problem in question.
When the report is developed using BIDS or viewed from Report Manager, a common rendering extension is used and when the report is exported to any other available format, it's corresponding rendering extension is used to generate the report output. Rendering extensions can be classified into two different modes known as "Interactive mode" and "Non-Interactive mode". Interactive means the report can be controlled by the end user such as an HTML report in a browser. Where non-interactive could be a report exported as a PDF file.
Based on certain properties of the global variable "RenderFormat" like "IsInteractive" or the "Name" property, if the visibility of a particular control on the report is hidden based on the "RenderFormat" that particular control would not display on an interactive report, but would display on a non-interactive report or vice versa. To test this, follow the below exercise.
1) Create a new blank report using Business Intelligence Development Studio (BIDS) and name it "ExportTest".
2) Add at least two controls to the report, so that we can test the difference. In my case I have added an image control and a text box control.
3) Deploy the report and view the report using report manager. You should be able to view the report with these two controls that were added.
4) Now go back to BIDS and select the Image control. Edit the "Hidden" property by clicking on the dropdown and select "Expression" as highlighted in the below screenshot.
5) Enter the expression as shown in the below screenshot. Our intention is to test the visibility of this image control when the report is viewed from Report Manager or from BIDS, and when the report is exported to some other format. After you have made the changes deploy the report again.
6) Now view this report from Report Manager. Both the controls should be visible as shown below.
7) Now export this report to a PDF format. The PDF format should show only the text in the exported report and not the image as shown in the below screenshot. The reason for this is that the PDF rendering extension is considered to not have interactive features. Now export the same report to a MHTML format and you will find that the image control is visible, because the MHTML format is considered to be an interactive format.
If you carefully analyze the steps we followed, you can start the analysis with the fact that PDF rendering format is not considered interactive. So the value of the "Globals!RenderFormat.IsInteractive" property got evaluated to "False" and the result of "NOT(False)" would be True. So when the value of the "Hidden" property is set to True, that would mean that the control should not be visible, which is apparent in the PDF report output. If you remove the "NOT" operator, you would achieve the opposite solution for the example that we discussed.
I hope you find a good use of this technique in your reports.
- Use the Name property of RenderFormat global variable to detect which RenderFormat is used in BIDS and Report Manager.
- Modify the expression such that image control should not be visible even in MHTML format.
Last Update: 9/3/2010
About the author
View all my tips