Publish report to Reporting Services in SharePoint Integrated Mode

Introduction

This VB.NET sample script illustrates how to publish a report from a computer path to Reporting Services in SharePoint integrated mode. This script applies to SQL Server Reporting Services 2008 R2 integrated with SharePoint 2010.

Scenarios

Starting from SQL Server 2008 R2, the rs utility is supported against report servers that are configured for SharePoint integrated mode as well as servers configured in
native mode. Today, most of the available script samples correspond to the native mode.  This sample script will ease the problems in below two scenarios:
1.The report server configured to SharePoint integrated mode.
2.The published report use embedded data source or shared data source.

Script

About how to run this script, please follow below steps:
Step1. On the Start menu, click All Programs, click Accessories, and then click Run. In the Open box, type CMD, and then click OK.
Screenshot:
 
Step2. Run the addpolicy.rss script file.
Command: rs -i E:\Onescript\PublishReportInIntegratedMode.rss -s localhost/reportserver -e Mgmt2010 -v newReportName_command="MyReport.rdl" -v sourceReportFullPath_command="E:\Projects\ForSharePoint\ForSharePoint\BuiltIn.rdl" -v destinationReportPath_command=http://servername/SSRSReports/onescript-v referenceDataSourceFullPath_command=http://servername/SSRSReports/onescript/datasource/hrDataSource.rsds
Screenshot:

Note: replace the values of the variables with yours.
-i: “E:\onescript\PublishReportInIntegratedMode.rss”, the PublishReportInIntegratedMode.rss script file locates in the local path E:\onescript.
-s: “localhost/reportserver” is the target report server URL.
-e: “Mgmt2010”, using SOAP endpoint Mgmt2010 for this script.
newReportName_command: The name of the new item.
sourceReportFullPath_command: the physical path of the report that you would like to publish to the report server.
destinationReportPath_command: the full folder path that you would like to publish the report to, it should be one path from the target report server.
referenceDataSourceFullPath_command: the full path of the referencing datasource. 
 
Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.
Visual Basic
Edit|Remove
'To read the source report into one [Byte]() data type variable definationTryDim stream As FileStream = File.OpenRead(sourceReportFullPath) 
         'Please note when we create one array such as array[Byte](6), there are 7 elements in this array actually 
         definition = New [Byte](stream.Length - 1) {} 
         stream.Read(definition, 0CInt(stream.Length)) 
         stream.Close() 
      Catch e As IOException 
         Console.WriteLine(e.Message) 
      EndTry

Additional Resources

rs Utility
Running a Reporting Services Script File
ReportingService2010.CreateCatalogItem Method
ReportingService2010.SetItemDataSources Method

Related forum threads:
http://social.technet.microsoft.com/Forums/en-US/sqlreportingservices/thread/44369a1f-94c6-416c-83e4-76ca3285fac1