|
Accessing Reports via URLs and Embedding Reports
|
|
In the last article titled,
Adding Parameters to a Report, we saw the basics of how to add
parameters to report to control the information that is shown to the report
user. We also saw how to create dependent parameters so that you can have
multiple parameters depending on each other for data display. We now have
enough information to see how to access reports via the URL directly. Why is
this required?? Usually, you access reports using the Report Manager
application which provides a web based interface for working with reports. The
URL based access is useful if you want to embed reports into
another application (like a web-based application or a forms-based
application).
In this article we will see how to access a report using its URL and then see an example of embedding a report into a Windows Forms application. I will assume that you are already familiar with using SQL Reporting Services. If you are not, please read the following articles (in the same order): Let us first build a report and test it so that we can then access it via its URL. The following are the steps you will need to follow to create this report.
You can now preview this report to see if everything is working fine. The following figure shows a sample product selected in my preview pane.
Looks like everything is fine! We will now see how to access the same report using the URL based access. Before doing this, we need to deploy the report. The folder structure for this project looks like the following on my machine (you might have a different structure based on your project name etc).
When you now deploy this project, a new folder called My Experiments is created in the report server and the report that we have developed (called ProductImages.rdl) will be placed. We need to understand this structure to properly specify the URL to access the report. The URL access syntax for Reporting Services contains a bunch of information that we need to know about. URL requests can contain multiple parameters that are listed in any order. Parameters are separated by an ampersand (&) and name/value pairs are separated by an equal sign (=). The basic syntax is as follows:
In the above syntax:
Ok, with this information, let us see how to get the URL for the report developed above. The following is the URL that you will need to type in your browser:
Note that /My Experiments/ProductImages constitutes the full path to access our report. The rc is a prefix that supplies a rendering extension with specific device information settings. Refer to the Reporting Services BOL for more information about the prefixes and what they mean. Finally, ProductID is the name of our parameter and 497 is the product ID that we are interested in. Here is another example that shows how to store the output of the report using the JPEG format.
When you execute the above URL, the browser will prompt
you for a dialog box that will allow you to save the output of the report to a
JPEG file.
Once we understand how the URL syntax works, it is very
easy to capitalize this on an application so that we can embed
reports of interest. Let us see an example of an application (Windows Forms)
that allows a user to type in a product number and then shows the report
designed above. To develop this application, create a Windows Forms application
with the following layout.
![]() Note that the blank space below the controls is the browser
control. When the user clicks on the Show Details
button, we point the browser to the appropriate URL and provide the parameter
from the text box as the product ID. This will then display the report on the
browser control. Here is the code for the button.
Note the usage of rc:Toolbar=false. This
parameter ensures that the toolbar that displays parameter info and other
details is not displayed. When you run this application and provide a product
ID, you will see the associated details as shown in the following figure.
![]() That's cool, isn'nt it?? Embedding reports can help you do
a lot of cool things inside your application without having to code for the
same. You can design the appropriate reports that aggregate data from various
sources and then embed them inside your application and reap all the benefits
of that data. Remember that the report however is still accessible via the
report manager application. Thus, its the best of both worlds!! Have fun!!
|
| Home |