To save a report as a Linked Report with different parameters would be a very nice feature to have in MS Reporting Services, but for some reason Microsoft decided to implement this in their default report viewer.
I first tried to modify the ReportViewer control but you can't really add any custom functionality to it. So I had to add a floating button at the approximate position on the Report Viewer toolbar.
1. Create basic page with a Report Viewer control. Download the ReportViewer control here and install it. Open a new ASP project in Visual Studio and add the control to default.aspx by dragging it from the toolbox > data section. Change the mode to server report and enter the address of your Reporting Services server.
2. Add the floating button. By using CSS, we can add an additional button to the webpage and make it blend with the rest of the tool bar.
<span ><blockquote style="color: rgb(0, 153, 0);">//HTML<div class="floater">
<input value="Save Link" id="save" class="button" onclick="Effect.Appear(document.getElementById('popup'))" type="button">
</div>
//CSS
.floater
{
vertical-align:middle;
float:right;
right:20px;
top: 40px;
width:50px;
height:50px;
position:absolute;
}
You get the point. I used scriptaculous for effects. Clicking the button with reveal a hidden div with a textbox to enter the name of the new linked report. Saving will call another .aspx file to save the report with a xmlHttp call.
3.
Function to save a linked report. I implemented this using AJAX and a different .aspx. I didn't really like to have the page refreshing. I'll explain further later on. First, we have to create a linked report. This is fairly easy to do with
CreateLinkedReport(NEWNAME, PATH, REPORT, props);
This creates a linked report called NEWNAME in PATH and it will be a copy of REPORT.
To save the parameters of the report, the best way is to run the report first and use ServerReport.GetParameters to get the last used parameters. You have to call GetParameters from the instance of your ReportViewer control.
ReportParameterInfoCollection ic = viewer1.ServerReport.GetParameters();
You will have to add a web reference to the Reporting Services web service. Click Project > Add Web Reference... and enter http://[server host]/Reportserver/Reportservice.asmx?WSDL. GetParameters gives you a collection of ReportParameterInfos. However, we need an array of ReportParameter objects to use SetReportParameters to set default parameters of the linked report.
4.
My Reports. Usually users will want to put their linked reports in their "My Reports" folder. each of these folder has permission settings that only allow the user to add reports. We will need to impersonate that user in order to put a new linked report in the folder. Add this line to your web.config
<system.web>
<identity impersonate="true">
</system.web>
and take off Allow Anynomous Access in your IIS settings.
For more information about any of the methods used, read MSDN. More info about AJAX on Google.