Programatically create SSRS report snapshot

' Created by Bert Van Landeghem 16/01/2015
' How to use:
' -i scriptfile
' -s https://SSRS_server_url/reportserver
' -v REPORT_PATH="path to report for which to create a snapshot"
'
' Example command line:
' "C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\rs.exe" -i C:\test\CreateReportSnapshot.rss -s http://reporting2012.localnet.be/ReportServer -v REPORT_PATH="/Lists/CentralPrint" 
'
' ReportingService2010 Methods (ReportService2010)
' [http://msdn.microsoft.com/en-us/library/reportservice2010.reportingservice2010_methods.aspx]
Public Sub Main() 
 Try
 rs.Credentials = System.Net.CredentialCache.DefaultCredentials 
 
 Console.WriteLine("----------------------------------------------------------------")
 Console.WriteLine("Script to create report snapshot")
 Console.WriteLine("----------------------------------------------------------------")
 Console.WriteLine("Connected to server : {0}",rs.url) 
 Console.WriteLine("SSRS server version : {0}",rs.GetType()) 
 Console.WriteLine("Parameter REPORT_PATH : {0}",REPORT_PATH)
 Console.WriteLine("----------------------------------------------------------------")
 Console.WriteLine("")
 Console.WriteLine("----------------------------------------------------------------")
 Console.WriteLine("Listing report snapshots")
 Console.WriteLine("----------------------------------------------------------------")
 
 Dim Snapshot as ItemHistorySnapshot
for each Snapshot in rs.ListItemHistory(REPORT_PATH)
 Console.WriteLine("ID:{0} , CREATIONDATE:{1} , SIZE:{2}" , Snapshot.HistoryID, Snapshot.CreationDate, Snapshot.Size)
 next
 
 Console.WriteLine("")
 Console.WriteLine("----------------------------------------------------------------")
 Console.WriteLine("Creating new report snapshot")
 Console.WriteLine("----------------------------------------------------------------")
Dim Warnings As Warning()
 Dim Warning As Warning
Dim CreateItemHistorySnapshot_ReturnValue As String 
 CreateItemHistorySnapshot_ReturnValue = rs.CreateItemHistorySnapshot(REPORT_PATH, Warnings)
If Not (warnings Is Nothing) Then
 Console.WriteLine("Warnings occurred during creation of snapshot:")
 for each warning in Warnings 
 Console.WriteLine("WARNING: {0}",warning.tostring())
 Next
 
 else 
 Console.WriteLine("New Snapshot ID: {0}", CreateItemHistorySnapshot_ReturnValue)
 
 end if
Console.WriteLine("----------------------------------------------------------------")
 
 Catch e as Exception
 
 Console.WriteLine(e.ToString()) 
 
 End try
End Sub
Advertisements

One thought on “Programatically create SSRS report snapshot

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s