新客网WWW.XKER.COM:致力做中国最专业的网络学院!
学院: 操作系统 - 网络应用 - 服务器 - 网络安全 - 工具软件 - 办公软件 - Web开发 - 数据库 - 网页设计 - 图形图像 - 媒体动画 - 硬件学堂 - 存储频道 - QQ专区
您的位置:首页 > 软件开发 > .Net开发 > Asp.net教程 > 正文:用脚本发布Reporting Services报表

用脚本发布Reporting Services报表

新客网 XKER.COM 2007-12-04 来源:博客网 收藏本文
Dim mDefinition As [Byte]() = Nothing
Dim mWarnings As Warning() = Nothing
Dim mParentPath As String = "/" + pParentFolder

Public Sub Main()Sub Main()
rs.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim name As String
Dim items As CatalogItem() = Nothing
Dim folderExist, dataSourceExist As Boolean

Try
items = rs.ListChildren("/", True) '列举ReportServer根目录下所有项,判断目标目录是否已存在
Dim i As Integer
For i = 0 To items.length - 1
If items(i).name.toUpper = pParentFolder.toUpper And items(i).Type = 1 Then '1表示Folder
folderExist = True
End If
If items(i).name.toUpper = pParentFolder.toUpper And items(i).Type = 5 Then '5表示DataSource
dataSourceExist = True
End If
Next
Catch e As SoapException
Console.WriteLine(e.Detail.InnerXml.ToString())
End Try

'创建目标目录
If folderExist Then
Console.WriteLine("FOLDER EXISTED!")
Else
Try
rs.CreateFolder(pParentFolder, "/", Nothing)
Console.WriteLine("FOLDER:{0} CREATED SUCCESSFULLY!", pParentFolder)
Catch e As Exception
Console.WriteLine(e.Message)
End Try
End If

'创建数据源
If folderExist And dataSourceExist And pOverwriteDataSource = False Then
Console.WriteLine("DATA SOURCE EXISTED!")
Else
CreateDataSource()
End If

Try
Dim di As DirectoryInfo
If pFilePath = "" Then di = New DirectoryInfo(".") Else di = New DirectoryInfo(pFilePath)
Dim files As FileInfo() = di.GetFiles("*.rdl")
Console.WriteLine("TOTAL REPORT FILES: {0}", files.Length)
Dim fiNext As FileInfo
For Each fiNext In files
DeployReport(Microsoft.VisualBasic.Left(fiNext.name, fiNext.name.length - 4))
Next
Catch e As Exception
Console.WriteLine(e.ToString())
End Try
End Sub

Public Sub CreateDataSource()Sub CreateDataSource()
Dim name As String = pDsName
Dim parent As String = "/" + pParentFolder

Dim mDefinition As New DataSourceDefinition()
mDefinition.CredentialRetrieval = CredentialRetrievalEnum.Store
mDefinition.UserName = pDsUserName
mDefinition.Password = pDsPwd
mDefinition.ConnectString = "data source=yourservername"
mDefinition.Enabled = True
mDefinition.EnabledSpecified = True
mDefinition.Extension = "ORACLE"
mDefinition.ImpersonateUser = False
mDefinition.ImpersonateUserSpecified = True
mDefinition.Prompt = Nothing
mDefinition.WindowsCredentials = False

Try
rs.CreateDataSource(pDsName, parent, True, mDefinition, Nothing)
Console.WriteLine("DATASOURCE:{0} CREATE SUCCESSFULLY!", name)
Catch e As Exception
Console.WriteLine(e.Message)
End Try
End Sub

Public Sub DeployReport()Sub DeployReport(ByVal reportName As String)
Try
Dim stream As FileStream = File.OpenRead(pFilePath + reportName + ".rdl")
mDefinition = New [Byte](stream.Length) {}
stream.Read(mDefinition, 0, CInt(stream.Length))
stream.Close()
Catch e As IOException
Console.WriteLine(e.Message)
End Try

Try
mWarnings = rs.CreateReport(reportName, mParentPath, True, mDefinition, Nothing)

If Not (mWarnings Is Nothing) Then
Dim warning As Warning
For Each warning In mWarnings
Console.WriteLine(warning.Message)
Next warning
Else
Console.WriteLine("DEPLOY REPORT:{0} SUCCESSFULLY!", reportName)
End If
Catch e As Exception
Console.WriteLine(e.Message)
End Try
End Sub



将上述代码保存成.rss文件,如deploy.rss,然后在命令行执行:
C:"Documents and Settings"xxx>rs -i yourrssfilepath"deploy.rss -s http://localhost/reportserver -v pParentFolder="RsSample" -v pOverwriteDataSource=true -v pDsName="DataSource1" -v pDsUserName="youroracleusername" -v pDsPwd=" youroracleuserpassword " -v pFilePath="yourreportfilespath"

输出:
folder existed
datasource:DataSource1 create successfully
total report files: 1
deploy report:Report1 successfully
命令已成功完成
收藏】 【评论】 【推荐】 【投稿】 【打印】 【关闭
发表评论
要记得去论坛讨论,点击注册新会员匿名评论
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
阅读排行
随机推荐
实用信息推荐