I was recently at a client site who, through a bit of a long story, didn’t have any local copies of their RDL files. However, they did have all their reports deployed to a server in native mode. The question became – what’s the easiest way to download all the RDL files? Fortunately, the answer was pretty easy – an RS.exe script.
RS.exe is a command line environment which gives you a reference to the SSRS web service. You can use this to do most everything on an SSRS server, including security, rendering reports, manage subscriptions, and, fortunately, download files. You simply provide a script file written in VB.NET.
The script file will automatically have a variable named "rs" which is the reference to the Reporting Services web service. You simply provide a Main method as the starting point and away you go.
The script to download all reports and save them to the same file structure looks like this.
Dim rootPath As String = "C:\Reports"
Dim items As CatalogItem() = _
For Each item As CatalogItem in items
If item.Type = ItemTypeEnum.Folder Then
Else If item.Type = ItemTypeEnum.Report Then
Sub CreateDirectory(path As String)
path = GetLocalPath(path)
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.Save(GetLocalPath(reportName) + ".rdl")
Function GetLocalPath(rsPath As String) As String
Return rootPath + rsPath.Replace("/", "\")
I've included a variable called RootPath. This can be updated to point at whatever fold you'd like to store your reports in.
The Main method retrieves the list of all children (reports, folders, etc.) on the server. It then loops through each item. If it's a folder, it creates the folder locally. If it's a report it downloads it by first grabbing the byte array, then storing it in a memory stream and saving it locally using the XmlDocument object.
To use the script, simply copy/paste into notepad and save it, or download it from below. Then you can call RS from the command-line in SQL as follows:
rs -s http://<server>/ReportServer -i <filename>
Where <server> is the name of your Report Server, and <filename> is the name of the script file. Let it run for a few minutes and you'll have all your RDL files ready to start importing into projects.
So if you don't have the RDL files for your reports locally, downloading them is as easy as using RS.exe.