How To Deploy a Folder of RDL files Using RS.exe – SSRS

It is relatively straightforward to automatically deploy a locally stored folder of RDL files to a reporting server without having to manually upload each one.

To do this we need to create two files.

  • .bat file to set off RS.exe
  • .rss file that holds the scripting information that is required

Create a folder on the c drive of your SSRS folder called DBAFire or similar.

In that folder take the text from below and put into a .bat file.

@echo off 
::Script Variables 
SET LOGFILE="C:\DBAFire\RS Scripter log.txt" 
SET REPORTSERVER=http://localhost/ReportServer 
SET RS="RS.EXE" 
SET TIMEOUT=60 
::Clear Log file 
IF EXIST %logfile% DEL %logfile% 
::Run Scripts
 %rs% -i "C:\DBAFire\SSRSDeploy.rss" -s "%REPORTSERVER%" 
ECHO Finished Load at TE% %TIME% >>%LOGFILE% 
ECHO. >>%LOGFILE% 
PAUSE 

Now you need two more things.

The folder of your RDL files. Put that also inside the folder you have created and call it “RDLs”

And you need the rss script. This is a basically a VB script that the RS.exe uses.

Create the script from the below code and call it SSRSDeploy.rss

 
'============================================================================= 
' Simplified and adapted from the MS sample script that can be found at https://msftrsprodsamples.codeplex.com/SourceControl/changeset/view/76849#458460 
' 
' This version will dynamically upload from a folder, rather than hardcoded rdl files names. 
Dim definition As [Byte]() = Nothing 
Dim warnings As Warning() = Nothing 
Dim parentFolder As String = "FolderName to Upload to" 
Dim parentPath As String = "/" + parentFolder 
Dim filePath As String = "C:\DBAFire\RDLs\" 
Dim fileName As String 


Public Sub Main() 
rs.Credentials = System.Net.CredentialCache.DefaultCredentials 

'Create the parent folder 

	Try rs.CreateFolder(parentFolder, "/", Nothing) 

		Console.WriteLine("Parent folder {0} created successfully", parentFolder) 

		Catch e As Exception 
		Console.WriteLine(e.Message) 
	End Try 

'Process the list of files found in the directory. 
Console.WriteLine("Getting Paths") 

Dim fileEntries As String() = System.IO.Directory.GetFiles(filePath) 
Dim fileName As String 

	For Each fileName In fileEntries 	
			fileName = filename.replace(".rdl", "") 
			FileName = filename.replace(filePath,"") 
				Console.WriteLine("Trying to deploy " & filename) 
			PublishReport(fileName) 
	Next fileName 
End Sub 

Public Sub PublishReport(ByVal reportName As String) 

Try 
Dim stream As FileStream = File.OpenRead(filePath + reportName + ".rdl") 
	definition = New [Byte](stream.Length - 1) {} 
	stream.Read(definition, 0, CInt(stream.Length)) stream.Close() 

	Catch e As IOException 

	Console.WriteLine(e.Message) 
End Try 

Try 
warnings = rs.CreateReport(reportName, parentPath, False, 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 successfully with no warnings", reportName) 

End 

If Catch e As Exception Console.WriteLine(e.Message) 
End Try 
End Sub
'
'
''''''''''''''''''''''''''''''''''''''''''''''''

Now to run you need to fill your RDLs folder up with the reports that you wish to upload.

Then fill out the variables. Mainly the Folder name to upload to in the .rss file.

You will also need to change the filepaths in both folders if you didn’t stick to c:\dbafire.

When you run the batch file make sure you run as Administrator.

Enjoy!

Expert Tip: Make sure your datasources are setup first if you are doing a migration. That will help things run smoothly first up.

If you have any questions feel free to ask.

Rob StGeorge
Senior SQL Server Database Administrator residing in Auckland, NZ

Leave a Reply