Saturday 12 December 2015

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



      This article explains how to download the all RDL files from ReportManager. We can download all the 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 two files
  1. Script File (For downloading all RDL Files)
  2. 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 “Download_all_RDL_files.rss”):

'Script Starting Point
'This script downloads the all RDL files from ReportServer

Sub Main()
    Dim items As CatalogItem() = _
        rs.ListChildren("/", true)

    For Each item As CatalogItem in items
        If item.Type = ItemTypeEnum.Folder Then
            CreateDirectory(item.Path)
        Else If item.Type = ItemTypeEnum.Report Then
            SaveReport(item.Path)
        End If
    Next
End Sub

Sub CreateDirectory(path As String)
    path = GetLocalPath(path)
    System.IO.Directory.CreateDirectory(path)
End Sub

Sub SaveReport(reportName As String)
    Dim reportDefinition As Byte()
    Dim document As New System.Xml.XmlDocument()

    reportDefinition = rs.GetReportDefinition(reportName)
    Dim stream As New MemoryStream(reportDefinition)

    document.Load(stream)
    document.Save(GetLocalPath(reportName) + ".rdl")
End Sub

Function GetLocalPath(rsPath As String) As String
    Return rootPath + rsPath.Replace("/", "\")
End Function

'End of the Script



2. Command to prepare BatchFile (Copy the below command and past it in text file and save with the name and extension as “DownloadRdlFiles.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" -s "http://admin-pc:8080/ReportServer" -i C:\Kiran\Technology\SQLServer\SSRS\DeploymentScript\Download_rdl_files\Download_all_RDL_files.rss -v rootPath="C:\Kiran\Technology\SQLServer\SSRS\DeploymentScript\Download_rdl_files\RDL_files\\"
Pause


After preparing two files (Script File and Batch File), edit the batch file and update the "Rs.exe file path, ReportServer URL, .RSS script file path and RootPath (Local path, where we need to keep the RDL files)".
  • Rs.exe file path: Update with the Rs.exe file path (file is located at \Program Files\Microsoft SQL Server\110\Tools\Binn)

  • ReportServer URL: Update with the required ReportServer URL (From where we need to download RDL files)

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

  • RootPath: Update with the required path (where we need to place the downloaded RDL files)

Sample Folder Structure:

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

Also:
Upload Multiple RDL Files from Local path to ReportServer (Using Rs.Exe Utility)

20 comments:

  1. Excelent, this worked. I only has had to add Username and Passwort in the Connection to the Report Server.
    Great Work, thanks

    ReplyDelete
    Replies
    1. where need to add user name & password

      Delete
    2. In the Batch file we can add UserName and Password.

      Example (Batch File Code):
      "C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\rs.exe" -s "http://admin-pc:8080/ReportServer" -u "Username" -p "Password" -i C:\Kiran\Technology\SQLServer\SSRS\DeploymentScript\Download_rdl_files\Download_all_RDL_files.rss -v rootPath="C:\Kiran\Technology\SQLServer\SSRS\DeploymentScript\Download_rdl_files\RDL_files\\"
      Pause

      Delete
  2. Great Job. Really good. we have multiple folders in reports server so that can it is possible that we can export the rdl of specific folder.

    ReplyDelete
    Replies
    1. Thanks. Yes we can export RDL files to specific folder, please find the below link.

      http://basic-ssrs.blogspot.in/2015/12/upload-multiple-rdl-files-from-local.html

      Delete
    2. Hey Kiran,
      I am not getting how to use reference from the multiple reports upload link you gave above. Do we have to declare file_path and root_path differently for downloading any specific folder rdl's.

      Delete
    3. I have update the Upload RDL file post, please go throw and let me know if you need any clarification.

      Brief description about uploading RDL Files:
      We need to prepare three files.
      • Script File: The script file picks the multiple RDL files from specific folder and uploads into target SSRS report server folder (source and target paths we need to update in the “Configuration File”)

      • Configuration File: we need to update this file with source RDL file path and report server path

      • Batch File: it invokes the RS.exe file based on the Script file.

      Delete
  3. Getting an error "Unrecognized argument files"

    ReplyDelete
    Replies
    1. Hi Brain,

      Please verify the rs.exe file path in your machine (Based on SQL Server/SSRS version path will change). If the file is located in different location then update the same location.

      If the rs.exe file is present in the same location, then verify the Script file and Batch file code.

      Delete
  4. Excellent tutorial to Download all RDL files. But I also want to download Data Sources(.rsds) from Report Manager. Can you please provide script for that?

    ReplyDelete
    Replies
    1. Thanks Vikas.

      Right now I don’t have the script to download the RDS files. Will work on it and update you.

      Delete
  5. Excellent work! I am able to download all the folders from my dev server whereas I am not able to download all the folders except User Folders from prod. Also in prod environment, I do not see Microsoft SQL Server\110\Tools\Binn instead I have Microsoft SQL Server\100\Tools\Binn. Any help would be appreciated

    ReplyDelete
    Replies
    1. Thanks Subrahmanyam,

      Based on SQL Server/SSRS Version, the rs.exe file path will change. I think your machine is having SQL Server 2008 version, due to that the file is present in different location

      Delete
  6. Thank you so much - saved me so much time!

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. I had to change Lines 6, 8 & 23 for this codfe to work with ReportingService2010.dll.

    Line 6 = If item.TypeName = "Folder" Then
    Line 8 = Else If item.TypeName = "Report" Then
    Line 23 = reportDefinition = rs.GetItemDefinition(reportName)

    ReplyDelete
  9. Good stuff

    Really helpful - Thanks

    ReplyDelete
  10. Looks like you still might answer questions about this. I am getting an error from the VB compiler Name 'rootPath' is not declared. then it shows the last line in the rss file where rootPath is used. I am passing a fully qualified path from the bat file
    -v rootFile="E:\imta\setup\imtareports\download"
    I'm at a loss

    ReplyDelete