Deploying PDFs, and more [SSRS]

One of my presentations last year covered the topic of automating SSRS deployments through the RS Utility

In that presentation I covered how to create data sources and how to deploy shared datasets and reports.  What I didn’t cover is how you’re supposed to deploy other items, such as images or PDFs.  Luckily I got inspired once more through a forum question, so here’s the script for exactly that!

For the interested reader: the scripts from my session can be downloaded through this follow-up post: Automating SSRS Deployment: Download.

The script below demonstrates how to deploy a PDF but the same technique can be used for any file type.

    'The following global variables need to be passed in through the rs command:
    'Dim name As String = "CatalogItem.pdf"
    'Dim parent As String = "/Test"

    Dim reportFile As String = "scripts\resources\" & Name

    Public Sub Main()
        Console.WriteLine("Running script DeployPDF.rss")

        Dim overwrite As Boolean = True
        Dim fileContent As Byte() = Nothing
        Dim warnings As Warning() = Nothing

        'Common CatalogItem properties
        Dim descprop As New [Property]
        descprop.Name = "Description"
        descprop.Value = ""
        Dim hiddenprop As New [Property]
        hiddenprop.Name = "Hidden"
        hiddenprop.Value = "False"

        'PDF-specific property
        Dim mimeTypeProp As New [Property]
        mimeTypeProp.Name = "MimeType"
        mimeTypeProp.Value = "application/pdf"

        Dim props(2) As [Property]
        props(0) = descprop
        props(1) = hiddenprop
        props(2) = mimeTypeProp

            'Read file from disk
            Dim stream As FileStream = File.OpenRead(reportFile)
            fileContent = New [Byte](stream.Length - 1) {}
            stream.Read(fileContent, 0, CInt(stream.Length))

            Dim item As CatalogItem
            item = RS.CreateCatalogItem("Resource", Name, Parent, overwrite, _
                                        fileContent, props, warnings)

            If Not (warnings Is Nothing) Then
                Dim warning As Warning
                For Each warning In warnings
                    Console.WriteLine("Warning: {0}", Warning.Message)
                Next warning
                Console.WriteLine("CatalogItem: {0} published successfully with no warnings" _
                                  , Name)
            End If

        Catch e As IOException
        Catch e As SoapException
            Console.WriteLine("Error : " + e.Detail.Item("ErrorCode").InnerText _
                              + " (" + e.Detail.Item("Message").InnerText + ")")
        End Try
    End Sub

The most important line in all of the above is the one that calls the CreateCatalogItem method.

The first parameter of that function is called ItemType.  To find out what the possibilities are we need to look at the ListItemTypes method:

Item Type Description
Component A report part.
DataSource A data source.
Folder A folder.
Model A model.
LinkedReport A linked report.
Report A report.
Resource A resource.
DataSet A shared dataset.
Site A SharePoint site.
Unknown An item not associated with any known type.


A PDF is a resource so that’s the one we need!  When we specify Resource as value for the ItemType parameter the function expects an additional property through the Properties array parameter.  This differs from the deployment of a report or dataset.  The additional property is called MimeType and for PDFs the MIME type is application/pdf.

The script above can be called from a batch (.cmd) file, here’s a possibility:

@echo off

::Script Variables
SET REPORTSERVER=http://YourServer/ReportServer

::default location on 32-bit machines -> SET RS="C:\Program Files\Microsoft SQL Server\100\Tools\Binn\RS.EXE"
::default location on 64-bit machines -> SET RS="C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\RS.EXE"
SET RS="C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\RS.EXE"

SET LOGFILE="SSRS_DeployLog.txt"

::Clear Log file
IF EXIST %logfile% DEL %logfile%

ECHO Starting deployment to %REPORTSERVER%

::Write Log Header
ECHO Starting deployment at %DATE% %TIME% >>%LOGFILE%
ECHO RS             = %RS% >>%LOGFILE%

::Run Scripts

ECHO ...deploying catalog items...

%RS% -i "%SCRIPTLOCATION%\DeployPDF.rss" -s %REPORTSERVER% -l %TIMEOUT% -e %ENDPOINT% -v name="SomePDF.pdf" -v parent="/Test" >>%LOGFILE% 2>&1

ECHO Finished deployment at %DATE% %TIME% >>%LOGFILE%

ECHO Deployment finished!  See %LOGFILE% for details.

That’s it for today, have fun!



Tags: , ,

  1. Josh’s avatar

    The variable for reportFile indicates the source file is already located in the report server catalog. Can this be modified to point at a source file located on a drive folder such as c:/reports? It’d be nice to automate those kinds of uploads as opposed to doing it manually or creating url links within pagination reports. Any suggestions?


  2. cheap red wedding invitations’s avatar

    It is something to be able to paint a particular picture, or to carve a statue, and so to make a few objects beautiful; but it is far more glorious to carve and paint the very atmosphere and medium through which we look, which morally we can do. To affect the quality of the day, that is the highest of arts.


  3. Aliza’s avatar

    Hi there everyone, it’s my first pay a quick visit at this site,
    andd piece of writing is really fruitful in support of
    me, keep up posting these articles or reviews.


  4. AlexiUrind66’s avatar

    Anybody home???

    Can’t find any URL.


  5. Mike’s avatar

    Thanks for this post dude. Much appreciated. I’ve managed to get my SSRS deployment script with RS.exe to do PDFs automatically now! Woop woop!


© 2008-2019 BI: Beer Intelligence? All Rights Reserved