Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Use rs.exe to publish ALL .rdl files in a folder

711 views
Skip to first unread message

willi...@optusnet.com.au

unread,
Sep 18, 2006, 1:00:43 AM9/18/06
to
Hi,

I wonder if this can be done.

I have around 200 .rdl files grouped under a folder called
c:\MS_Reports and I want to publish them all onto my testing reporting
server using the script for publishing reports.

Folloing the MSDN documentation
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/rsamples/htm/rss_sampleapps_v1_1apd.asp,
I manage to modify the Publish Report call e.g

'PublishReport("Report1")
'PublishReport("Report2")
PublishReport("BOM_Report")

in the PublishSampleReports.rss and publish the BOM_Report.

The problem is there are around 200 .rdl reports and I don't want to
key in the report name one by one in the .rss file. In addition,
because eventually, I want to automatic this publishing report by
scheduling a batch job at night to run

"rs -i PublishSampleReports.rss -s http://myserver..."

so all of the .rdl in the report folder will get published.

Can this be done by modify the .rss script file? If yes, any hints on
how to do this? I am not good on the scripting language... :(

Thanks and regards,
Bill

Kaisa M. Lindahl Lervik

unread,
Sep 18, 2006, 10:12:56 AM9/18/06
to
I played with this a few months ago.
I ended up creating two scripts, one based on vbscript that made a txt-file
with all report names, and the rss file which read the file names from the
txt-file and pushes the reports to the right place on the server.

I ran into some problems with non-standard characters, and read and write
permissions, but it worked fairly well. If the name of the data sources
isn't correct, the reports will still be pushed to the server, and you have
to fix the data sources. There might also be a problem to upload reports
from a dev box that runs RS 2005 to a server that runs RS 2000, but you can
upload the reports from the server, so that should be a problem anyway. The
script code that triggers the rss file might not work either, so I added a
line of code with the correct syntax in the rss file.

Copy the code from the message below. Save the first one as
GetAllReportFiles.vbs and the second as PublishStandardReports.rss. Modify
the parameters in both files. Drag and drop the vbs-file into the command
prompt to run it. Even if it doesn't work on the first go, I hope this helps
you to get it right in the end. :)

The VBS-file: GetAllReportFiles.vbs

'*********************************************
' Created by Kaisa M. Lindahl Lervik, December 2005
' Script writes filenames of all Reporting Services reports to file
ListOfReports.txt
' Then starts Reporting Services script to deploy all reports to Report
Manager
'*********************************************

option explicit

dim shell, fso
set shell = createobject("wscript.shell")
set fso = createobject("scripting.filesystemobject")

'setup...
'
dim outfile, path, spec, scriptFileName, serverName, parentFolder
outfile = "C:\Data\ReportProjects\MyReports\ListOfReports.txt"
path = "C:\Data\ReportProjects\MyReports\"
spec = "*.rdl"
scriptFileName = "C:\Install\Script\PublishStandardReports.rss"
serverName = "http://MyServer/reportserver/"
parentFolder = "Standard"

'drive dir command and capture output...
'
'shell.Run "%comspec% /c chcp 1252"

shell.run "%comspec% /c chcp 1252 | dir " _
& chr(34) & path & spec & chr(34) _
& " /b /on >" & outfile,_
0,true

'check for empty capture file...
'
if fso.getfile(outfile).size = 0 then
msgbox "no matches!..."
wscript.quit
end if

'read into an array
'
dim fnames
fnames = split(fso.opentextfile(outfile).readall,vbcrlf)

'drop last (empty) array element...
'(caused by crlf on last line)
'
redim preserve fnames(ubound(fnames)-1)

'get the folder...
'
dim folder
set folder = fso.getfolder(path)

'walk array of filtered/sorted file names
'and use each to index the files collection...
'
dim fname, s, br, rName, x
for each fname in fnames
' s = s & br & folder.files((fname)).path
x = split(fname, ".",2)
rName = x(0)
s = s & br & rName
br = vbcrlf
next

'show results...
'
msgbox s
path = Mid(path, 1, (len(Path)-1))
' Start the Reporting Services script
shell.run "%comspec% /c rs -i " & scriptFileName & " -s " & serverName &
" -v parentFolder=""" & parentFolder & """ -v listOfReports=""" & outFile &
""" -v pathToReports=""" & path & """"

'cleanup...
'
'fso.deletefile outfile
set shell = nothing
set fso = nothing
set folder = nothing

**************************
Updated RSS file: PublishStandardReports.rss

'=====================================================================
' File: PublishStandardReports.rss
'
' Summary: Demonstrates a script that can be used with RS.exe to
' publish the sample reports that ship with Reporting Services.
' Modified by Kaisa M. Lindahl Lervik to read report names from txt file
'---------------------------------------------------------------------
' This file is part of Microsoft SQL Server Code Samples.
'
' Copyright (C) Microsoft Corporation. All rights reserved.
'
' This source code is intended only as a supplement to Microsoft
' Development Tools and/or on-line documentation. See these other
' materials for detailed information regarding Microsoft code samples.
'
' THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
' KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
' IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
' PARTICULAR PURPOSE.
'=====================================================================*/
'Call the script with this command:
'rs -i C:\Install\Skript\publishStandardReports.rss -s
http://MyServer/reportserver/ -v parentFolder="Standard" -v
listOfReports="C:\Data\ReportProjects\MyReports\ListOfReports.txt" -v
pathToReports="C:\Data\ReportProjects\MyReports"
'


'Option explicit


Dim definition As [Byte]() = Nothing
Dim warnings As Warning() = Nothing
Dim parentPath As String = "/" + parentFolder
Dim filePath As String = pathToReports & "\"
dim fileListOfReports as String = listOfReports


Public Sub Main()

rs.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim name As String

'Create the parent folder
Try
rs.CreateFolder(parentFolder, "/", Nothing)
Console.WriteLine("Parent folder created: {0}", parentFolder)
Catch e As Exception
Console.WriteLine(e.Message)
End Try

'Create the shared data sources
CreateDataSourceSQL()
CreateDataSourceOLAP()

'Publish reports
PublishReports(fileListOfReports )
End Sub

Public Sub CreateDataSourceSQL()
Dim name As String = "MyDB"
Dim parent As String = "/" + parentFolder

'Define the data source definition.
Dim definition As New DataSourceDefinition()
definition.CredentialRetrieval = CredentialRetrievalEnum.Integrated
definition.ConnectString = "data source=(local);initial catalog=MyDB"
definition.Enabled = True
definition.EnabledSpecified = True
definition.Extension = "SQL"
definition.ImpersonateUser = False
definition.ImpersonateUserSpecified = True
'Use the default prompt string.
definition.Prompt = Nothing
definition.WindowsCredentials = False

Try
rs.CreateDataSource(name, parent, False, definition, Nothing)

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

End Sub
Public Sub CreateDataSourceOLAP()
Dim name As String = "OLAP"
Dim parent As String = "/" + parentFolder

'Define the data source definition.
Dim definition As New DataSourceDefinition()
definition.CredentialRetrieval = CredentialRetrievalEnum.Integrated
definition.ConnectString = "Provider=MSOLAP.2;Client Cache Size=25;Data
Source=MyAS;Initial Catalog=OLAP;Auto Synch Period=10000"
definition.Enabled = True
definition.EnabledSpecified = True
definition.Extension = "OLEDB"
definition.ImpersonateUser = False
definition.ImpersonateUserSpecified = True
'Use the default prompt string.
definition.Prompt = Nothing
definition.WindowsCredentials = False

Try
rs.CreateDataSource(name, parent, False, definition, Nothing)

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

End Sub
Public Sub PublishReports(ByVal reportFileName As String)
Try
dim reportStream as StreamReader = New StreamReader(reportFilename)
dim line, reportName as String

Do
line = reportStream.ReadLine()
reportName = line.Replace(".rdl", "")

Try
Dim stream As FileStream = File.OpenRead(filePath + line)
definition = New [Byte](stream.Length) {}
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
Loop Until line Is Nothing
reportStream.Close()

Catch e as Exception
Console.WriteLine(e.Message)
End Try
End Sub

*************************************


Kaisa M. Lindahl Lervik


<willi...@optusnet.com.au> wrote in message
news:1158555643....@e3g2000cwe.googlegroups.com...

techman

unread,
Sep 18, 2006, 9:57:13 PM9/18/06
to
Hi Kaisa,

Many thanks for the help. The two scripts work really well and I can
publish all of the rdl in a folder all in a go.

Thanks again.
Bill

0 new messages