Saturday 12 December 2015

Upload Multiple RDL Files from Local path to ReportServer (Using RS.exe Utility)



      This article explains how to Upload/Deploy the multiple RDL files from local machine to ReportManager. We can Upload/Deploy multiple RDL files at a time using RS.exe utility. RS.exe utility is a command line utility that can perform many scripted operation related to SQL Server Reporting Services (SSRS).

Note: Rs.exe file path will change based on the SQL Server/SSRS version

EXE file is located any one of the below locations (Based on SQL Server/SSRS Version):
For 64 Bit: \Program Files\Microsoft SQL Server\100\Tools\Binn
For 32 Bit: \Program Files (x86)\Microsoft SQL Server\100\Tools\Binn
OR
For 64 Bit: \Program Files\Microsoft SQL Server\110\Tools\Binn
For 32 Bit: \Program Files (x86)\Microsoft SQL Server\110\Tools\Binn
OR
For 64 Bit: \Program Files\Microsoft SQL Server\120\Tools\Binn
For 32 Bit: \Program Files (x86)\Microsoft SQL Server\120\Tools\Binn

For this process we need to prepare three files
  1. Script File (For uploading all RDL Files)
  2. Configuration file (We need to specify the "Local folder path and ReportManager folder path")
  3. Batch file (To execute the RS.exe based on script present in the script file)

1. Script to prepare ScriptFile (Copy the below script and past it in text file and save with the name and extension as “Upload_Multiple_RDL_files.rss”):

'Script Starting Point
' Script to deploy report to report server
' EXECUTE VIA COMMAND LINE

DIM definition As [Byte]() = Nothing
DIM warnings As Warning() = Nothing

Public Sub Main()

' Variable Declaration
        Dim TextLine As String = ""
        Dim LocalDir As String = ""
        Dim ServerDir As String = ""
        Dim definition As [Byte]() = Nothing
        'Dim warnings As Warning() = Nothing

' Reading Configuration Text file and assigning the values to variables
        If System.IO.File.Exists(FILE_NAME) = True Then
            Dim objReader As New System.IO.StreamReader(FILE_NAME)
            Do While objReader.Peek() <> -1
                TextLine = objReader.ReadLine()
                Dim parts As String() = TextLine.Split(New Char() {","c})
                'TextLine & objReader.ReadLine() '& vbNewLine
                LocalDir = parts(0)
                ServerDir = parts(1)

                Dim path As String = LocalDir
                Dim fileEntries As String() = Directory.GetFiles(path)
                Dim fileFullPath As String = ""
                For Each fileFullPath In fileEntries


 ' Deploying the Reports
                    Try
                        Dim stream As FileStream = File.OpenRead(fileFullPath)
                        Dim NameWithExt As String = fileFullPath.Replace(path, "")
                        Dim NameOnly As String = NameWithExt.Replace(".rdl", "")
                        definition = New [Byte](stream.Length) {}
                        stream.Read(definition, 0, CInt(stream.Length))

warnings = rs.CreateReport(NameOnly, ServerDir, True, definition, Nothing)

If Not (warnings Is Nothing) Then
DIM warning As Warning
For Each warning In warnings
Console.WriteLine(warning.Message)
Next warning
Else
Console.WriteLine("Report: {0} PUBLISHED!", NameOnly)
End If

Catch e As IOException
Console.WriteLine(e.Message)
End Try
Next fileFullPath
Loop
         Else

            Dim MsgBox as String = "File Does Not Exist"

        End If
End Sub

'End of the Script



2. Configuration file: In this file we need to specify the source folder path (where the RDL files are located) and Target (ReportServer path, to where we need to upload the RDL files) with comma separate. Please refer the below attached images.

In this example, i have RDL files in two different folders and i want to upload them into different target folders in the report server.

Local Machine Path:
C:\Kiran\Technology\SQLServer\SSRS\DeploymentScript\Upload_Multiple_RDL_Files\SSRS\SalesReports\
C:\Kiran\Technology\SQLServer\SSRS\DeploymentScript\Upload_Multiple_RDL_Files\SSRS\Aggregate\

Report Server Path:
/SSRS/SalesReports
/SSRS/Aggregate






3. Command to prepare BatchFile (Copy the below command and past it in text file and save with the name and extension as “UploadRDLFiles.bat”):
Note: Verify the rs.exe file path in your Machine and Update the below path if the file is present in different location.

"C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\rs.exe" -i C:\Kiran\Technology\SQLServer\SSRS\DeploymentScript\Upload_Multiple_RDL_Files\Upload_Multiple_RDL_files.rss -s "http://admin-pc:8080/ReportServer" -v FILE_NAME="C:\Kiran\Technology\SQLServer\SSRS\DeploymentScript\Upload_Multiple_RDL_Files\ConfigurationFile.txt"

Pause




After preparing the three files (Script File, Configuration file and Batch File), edit the batch file and update the "Rs.exe file path, .RSS script file path, ReportServer URL,  and Configuration file path".
  • Rs.exe file path: Update with the Rs.exe file path (file is located at \Program Files\Microsoft SQL Server\110\Tools\Binn)

  • .RSS script file path: Update with the .rss script file path (where we placed the ScriptFile "Upload_Multiple_RDL_files.rssfile).

  • ReportServer URL: Update with the required ReportServer URL (To where we need to upload the RDL files).

  • Configuration file path: Update the file with required source and targets paths.

Sample Screenshot of the files:

After Updating the Script and Batch files, double click on the batch file then execution will start.

Note: We are uploading/Deploying only RDL files, so we may receive the below message. We can ignore that.

Message:

The dataset “<<Dataset name>>” refers to the shared data source “<<Dataset name>>”, which is not published on the report server. The shared data source “<<Dataset name>>” must be published before this report can run.

Note: If the Reports are referring to share data sources those may not work, if so edit RDL files Data source from report manager and updated with appropriate Data source.

See Also:
Download the all RDL files from ReportManager (Using RS.exe Utility)

5 comments:

  1. Holy hell this is a lot of work to upload multiple files. Why on Earth didn't Microsoft provide some sort of FTP drag and drop interface to easily move files on report server?

    ReplyDelete
  2. the VB script publish's only the first rdl file ignoring the rest from the local folder.

    ReplyDelete
  3. infact, once when you include all RDLs in a Report Project and deploy directly mentioning all required details, it works.

    ReplyDelete
  4. The above script does not seem to work on new version of windows or SQL - I have a site that is running Server 2022 and SQL 2019 and when I run the bat then I get
    Any Advice??

    This method explicitly uses CAS policy, which has been obsoleted by the .NET Framework. In order to enable CAS policy for compatibility reasons, please use the NetFx40_LegacySecurityPolicy configuration switch. Please see http://go.microsoft.com/fwlink/?LinkID=155570 for more information

    ReplyDelete
    Replies
    1. this link might help you with your issue

      https://codegumbo.com/index.php/2020/02/10/uploading-multiple-rdl-files-to-ssrs/

      the only update here is the adding of -1 in this line of code

      definition = New [Byte](stream.Length-1) {}

      Delete