locked
Automatic file upload to report server RRS feed

  • Question

  • Hi,

    I have txt, xls and pdf files that i need to upload into an existing report server folder, so that it can be accessed and downloaded from report manager.

    Is this possible to do via rsutility ?

    If so, can anyone help on how to go about doing this, ideally from within an ssis package ?

    regard

    Wednesday, April 3, 2013 10:17 AM

Answers

  • Yes, you can deploy txt, slx and pdf file via rsutility. You can define scripts to set system properties, publish reports, and so forth. The script must be written in Visual Basic .NET code, and stored in a Unicode or UTF-8 text file with an .rss file name extension. Here has the sample code for, you can change *.rdl in the code to *.txt or other type file.

    Dim parentFolder As String = "Sales and Order Quantity Analysis"
    Dim parentPath As String = "/" + parentFolder
    Dim filePath As String = parentFolder
    Dim definition As [Byte]() = Nothing
    Dim dsReference As String = "/Data Sources/AdventureWorksDW2008"
    Dim dsReferenceName As String = "AdventureWorksDW2008"
    
    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
        
        'Publish the sample reports
        PublishFolder(filePath)
        
    
    End Sub
    
    Public Sub PublishFolder(ByVal folderPath as String)
    	Dim sourceFolder as System.IO.Directory
    	Dim reports As String() = sourceFolder.GetFiles(folderPath, "*.rdl")
    	Dim report As String
    	For Each report In reports
    		PublishReport(report)
    	Next
    End Sub
    
    Public Sub PublishReport(ByVal reportPath As String)
        Try
            Dim stream As FileStream = File.OpenRead(reportPath)
            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
            Dim reportPieces As String() = Microsoft.VisualBasic.Strings.Split(reportPath, "\")
    		Dim reportName As String = reportPieces.GetValue(reportPieces.Length - 1)
    		reportName = reportName.Substring(0, reportName.Length - 4)
    
    		rs.CreateReport(reportName, parentPath, False, definition, Nothing)
    		
    	
    		Dim ds() AS DataSource = rs.GetItemDataSources(parentPath + "/" + reportName)
    		
    		
    		Dim dsRef AS DataSourceReference = New DataSourceReference()
    		dsRef.Reference = dsReference
    		ds(0).Item = dsRef
    		rs.SetItemDataSources(parentPath + "/" + reportName, ds)
    		
            Console.WriteLine("Report: {0} published successfully", reportName)
            
    
        Catch e As Exception
            Console.WriteLine(e.Message)
        End Try
    End Sub

    • Proposed as answer by Charlie Liao Tuesday, April 9, 2013 7:37 AM
    • Marked as answer by Charlie Liao Monday, April 15, 2013 1:26 AM
    Tuesday, April 9, 2013 7:07 AM