If items(i).Name.ToUpper = strAimReportsFolder.ToUpper And items(i).Type = ItemTypeEnum.Folder Then
oAimReportsFolderExists = True End If
'是数据源类型
If items(i).Name.ToUpper = strAimFolder.ToUpper And items(i).Type = ItemTypeEnum.DataSource Then
oDataSourceExists = True End If Next
Catch ex As Exception
Console.WriteLine(ex.Message.ToString) End Try
'创建数据源目标目录 If oAimFolderExists Then
Console.WriteLine(\目录\已经存在!\ Else Try
rs.CreateFolder(strAimFolder, \ Catch ex As Exception
Console.WriteLine(ex.Message.ToString) End Try End If
'创建报表目标目录
If oAimReportsFolderExists Then
Console.WriteLine(\目录\已经存在!\ Else Try
rs.CreateFolder(strAimReportsFolder, \ Catch ex As Exception
Console.WriteLine(ex.Message.ToString) End Try End If
'创建数据源
If oAimFolderExists And oDataSourceExists And oOverWriteDataSource = False Then Console.WriteLine(\数据源已经存在!\ Else
CreateDataSource()
End If
'发布报表 Try
Dim oDirectoryInfo As DirectoryInfo
If strReportsFilePath = \
oDirectoryInfo = New DirectoryInfo(\ Else
oDirectoryInfo = New DirectoryInfo(strReportsFilePath) End If
Dim files As FileInfo() = oDirectoryInfo.GetFiles(\
Console.WriteLine(\总共报表数量: {0}\
Dim fiNext As FileInfo
'循环发布报表
For Each fiNext In files
DeployReport(Microsoft.VisualBasic.Left(fiNext.Name, fiNext.Name.Length - 4))
Next
'将报表引用已创建的数据源
Dim reference As New DataSourceReference
reference.Reference = strParentPath & \
Dim subItems As CatalogItem() = rs.ListChildren(strParentReportsPath, False) For Each item As CatalogItem In subItems If item.Type = ItemTypeEnum.Report Then
Dim dataSources As DataSource() = rs.GetItemDataSources(item.Path) For Each datasource As DataSource In dataSources datasource.Item = reference Next
rs.SetItemDataSources(item.Path, dataSources) End If Next
Catch ex As Exception
Console.WriteLine(ex.Message.ToString) End Try
End Sub
Public Sub CreateDataSource()
'Dim folderPath As String = \
Dim csrdb As New DataSourceDefinition
csrdb.ConnectString = \strServerName
csrdb.Extension = \
csrdb.CredentialRetrieval = CredentialRetrievalEnum.Store csrdb.Enabled = True
csrdb.EnabledSpecified = True
csrdb.ImpersonateUserSpecified = False csrdb.UserName = strDataSourceUserName csrdb.Password = strDataSourcePassword
'csrdb.CredentialRetrieval = CredentialRetrievalEnum.Integrated Try
rs.CreateDataSource(strDataSourceName, strParentPath, True, csrdb, Nothing) Catch ex As Exception
Console.WriteLine(ex.Message.ToString) End Try End Sub
Public Sub DeployReport(ByVal strReportName As String) Try
Dim stream As FileStream = File.OpenRead(strReportsFilePath & \& strReportName & \
mDefinition = New [Byte](stream.Length) {} stream.Read(mDefinition, 0, CInt(stream.Length)) stream.Close() Catch ex As IOException
Console.WriteLine(ex.Message.ToString) End Try
Try
mWarnings = rs.CreateReport(strReportName, strParentReportsPath, 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