Thursday 6 October 2011

Copy SSRS Report on Report Server Programatically

This post explains about programmatically copying a SSRS report(deployed on 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.
Follow the steps provided below:
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. 
        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 service 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 copy a existing Report (which is deployed on Report Server)

Following code copies a SSRS named “EmployeeReport” located inside “TestReports” folder as  CopiedEmployeeReport” which will be located inside “TestSSRSProject” project
//Create Proxy object for ReportingService
ReportingService.ReportingService2010 rs;
rs = new ReportingService.ReportingService2010();
//Path of source report(i.e. Report that need to be copied)
//Set the Credentials for authentication of reportingService
rs.Credentials Net.CredentialCache.DefaultNetworkCredentials;//Above you can also provide the credentials as below
//System.Net.NetworkCredential Mycredentials = new System.Net.NetworkCredential("yourUserName", "yourPassword", "yourDomainName");
//          rs.Credentials = Mycredentials;
 
 

string _reportPath = null;
_reportPath = "/TestReports/EmployeeReport";

//Get source report definition as Byte array
Byte[] reportDefinition = null;
reportDefinition = rs.GetItemDefinition(_reportPath);

//Get report Data source of source report
ReportingService.DataSource[] ds = null;
ds = rs.GetItemDataSources(_reportPath);


ReportingService.Warning[] warnings = null;

//Copies “EmployeeReport”  report as "CopiedEmployeeReport" inside "/TestSSRSProject" folder
ReportingService.CatalogItem copiedReport = rs.CreateCatalogItem("Report", "CopiedEmployeeReport", "/TestSSRSProject", false, reportDefinition, null, warnings);
 //Set Data Source of copied report
rs.SetItemDataSources("/TestSSRSProject/CopiedEmployeeReport", ds);


Please let me know whether this was helpful , so that i can post more related topics????



2 comments:

  1. FYI, this was helpful. When managing subscriptions in a heavy user data environment, this will be helpful.

    ReplyDelete
  2. very helpful1

    ReplyDelete