Friday, March 23, 2012

problems with Publish Reports Script File

How do i make the datasources same path for each report loaded
I have 5 group sets
I end up manually change the datasource for each one
If i can make this script files to do it

what changes do i need to make ?

__
' Publish Reports
' Adapted from Microsoft Publish Reports Sample Script File


Dim parentfolder as string
Dim definition As [Byte]() = Nothing
Dim warnings As Warning() = Nothing
Dim parentPath As String = "/" + parentFolder
Dim filePath As String

Public Sub Main()

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


parentfolder = "DataSources"
parentpath = "/" + parentFolder

'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

CreateSampleDataSource()


'Publish the sample reports

parentfolder = "Polling Reports"
parentpath = "/" + parentFolder
'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

filePath = "c:\apps\Corr6\Server\Reporting Services\Polling Reports\"


PublishReport("Polling Interest")

parentfolder = "Mail Reports"
parentpath = "/" + parentFolder
'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

filePath = "c:\apps\Corr6\Server\Reporting Services\Mail Reports\"


PublishReport("Code Usage")
PublishReport("Communication History")
PublishReport("Mail Staff Load")
PublishReport("Outstanding Mail Staff")
PublishReport("Outstanding Mail Summary")
PublishReport("Top Code Usage")
PublishReport("Group Mail Summary")

parentfolder = "Casework Reports"
parentpath = "/" + parentFolder
'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


filePath = "c:\apps\Corr6\Server\Reporting Services\Casework Reports\"

PublishReport("Casework Closed")
PublishReport("Casework County")
PublishReport("Casework Detail")
PublishReport("Casework Outstanding")
PublishReport("Casework Staff")
PublishReport("Casework Summary")

parentfolder = "WorkFlow Reports"
parentpath = "/" + parentFolder
'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


filePath = "c:\apps\Corr6\Server\Reporting Services\workflow reports\"

PublishReport("Staff Productivity Report")
PublishReport("Overdue Tasks")

parentfolder = "System Reports"
parentpath = "/" + parentFolder
'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

filePath = "c:\apps\Corr6\Server\Reporting Services\System Reports\"
PublishReport("Interest System Codes")
PublishReport("Letter System Codes")
PublishReport("Personal System Codes")
PublishReport("System Staff")

End Sub

Public Sub CreateSampleDataSource()
Dim name As String = "DataSource"
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=cap_win"
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 PublishReport(ByVal reportName As String)
Try
Dim stream As FileStream = File.OpenRead(filePath + reportName + ".rdl")
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
End Sub

Anybody know what to do ?|||

can it be done ?
any reference where i might get the answer ?

No comments:

Post a Comment