Sunday, 25 September 2011

Copy SSRS Report using ReportingService

Copy SSRS Report using ReportingService.CreateCatalogItem() method

This post explains about programmatically copying a existing SSRS report (which is deployed on the report server) using Reporting Services Web service.
PreRequisite : You must have SSRS(SQL Server Reporting Services) installed so that you can use Reporting web services provided by SSRS.

Step 1: Add Reference to Web Service()
The first thing you need to do is add a Web reference to the Reporting Services Web service in your development project that points to your report server. 
To do so right-click on your project in Visual Studio and choose Add Service reference... .Then Click on Advanced  and then "Add Web Reference.." as shown in below image..

Provide report server URL (in my case http://localhost/reportserver/ReportService2010.asmx). If you have a remote report server, simply change the URL of the Web reference. The end point for any Reporting Services Web service is http://servername/reportserver/ReportService2010.asmx.
Provide service reference name(i provided "ExecutionService" as reference name) and click on Add.

Step 2: Using  ReportingService.CreateCatalogItem method To create new Report
 Here i am going to copy a report named "EmployeeReport" (deployed at report server in TestReports folder) and create a new copied report from it named "CopiedEmployeeReport" inside "TestSSRSProject" folder....
//create proxy object
ReportingService.ReportingService2010 rs = new ReportingService.ReportingService2010();
//set credentials and URL for reporting service.
rs.Credentials = Net.CredentialCache.DefaultNetworkCredentials;

//Provide path of report to be copied(source report)
string _reportPath = "";
_reportPath = "/TestReports/EmployeeReport";

//Report definition of report to be copied..
Byte[] reportDefinition = null;
reportDefinition = rs.GetItemDefinition(_reportPath);
ReportingService.DataSource[] ds = null;
ds = rs.GetItemDataSources(_reportPath);

ReportingService.Warning[] warnings = null;

//Create new report from report definition obtained in previous step and set datasource.
ReportingService.CatalogItem copiedReport = rs.CreateCatalogItem("Report", "CopiedEmployeeReport", "/TestSSRSProject", false, reportDefinition, null, warnings);

rs.SetItemDataSources("/TestSSRSProject/CopiedEmployeeReport", ds);
Similarly you can create a new report using rs.CreateCatalogItem() method..
Let me know if you need any help...

No comments:

Post a Comment