Sub Main() rs.Credentials = System.Net.CredentialCache.DefaultCredentials Dim dataSourceName As String = "reportsdb" Dim folderName As String = "Company Reports" Dim folderPath As String = "/" & folderName 'create the folder "Company Reports" Try rs.CreateFolder(folderName, "/", Nothing) Console.WriteLine("Company Reports folder created.") ' 'Both the reports and the Data Source are being deployed in this script. 'Here, the Data Source is created in the new folder. ' 'add the datasource "reportsdb" to the "Company Reports" folder Dim csrdb As New DataSourceDefinition csrdb.ConnectString = "Initial Catalog=reportsdb;Data Source=localhost" csrdb.Extension = "SQL" csrdb.CredentialRetrieval = CredentialRetrievalEnum.Integrated rs.CreateDataSource(dataSourceName, folderPath, True, csrdb, Nothing) Console.WriteLine("reportsdb data source created.") Catch ex As System.Exception End Try ' 'Now the code goes to the source folder and loops through each .rdl file and deploys it. ' 'upload the rdl files Dim files() As String files = Directory.GetFiles _ (Directory.GetCurrentDirectory() & "\Catalog Items") Dim len As Integer = files.Length - 1 Dim i As Integer 'loop through each file. For i = 0 To len 'load the file into a byte array Dim fs As FileStream = File.Open(files(i), FileMode.Open) Dim data(fs.Length - 1) As Byte fs.Read(data, 0, fs.Length) 'retreive the report name Dim itemName As String = GetShortFileName(files(i)) Dim extension As String = GetExtension(files(i)) If extension = "rdl" Then 'create the report rs.CreateReport(itemName, folderPath, True, data, Nothing) Else Dim mimeType = GetMimetype(files(i)) rs.CreateResource _ (itemName, folderPath, True, data, mimeType, Nothing) End If Console.WriteLine(itemName & " was created in: " & folderPath) fs.Close() Next ' 'Changing the Data Source property for multiple deployed reports can be a hassle. 'Here that task has been added to the script, automating that part of the process as well. ' 'set the datasources to "reportsdb" Dim reference As New DataSourceReference reference.Reference = folderPath & "/" & dataSourceName Dim items As CatalogItem() = rs.ListChildren(folderPath, False) For Each item As CatalogItem In items If item.Type = ItemTypeEnum.Report Then Dim dataSources As DataSource() = _ rs.GetReportDataSources(item.Path) For Each dataSource As DataSource In dataSources dataSource.Item = reference Next rs.SetReportDataSources(item.Path, dataSources) Console.WriteLine(item.Name & " datasource was updated") End If Next End Sub ' 'These are the helper functions that provide string parsing and mime type checking. ' Private Function GetShortFileName(ByVal fullFileName As String) As String 'get the report name Dim slashPos As Integer = fullFileName.LastIndexOf("\") Dim dotPos As Integer = fullFileName.LastIndexOf(".") Dim retVal As String = fullFileName.Substring _ (slashPos + 1, dotPos - slashPos - 1) Return retVal End Function Private Function GetExtension(ByVal fullFileName As String) As String Dim retVal As String = fullFileName.Substring _ (fullFileName.LastIndexOf(".") + 1) Return retVal End Function Private Function GetMimetype(ByVal fullFileName As String) As String Dim extension As String = GetExtension(fullFileName) Dim retVal As String Select Case extension Case "htm" retVal = "text/html" Case "html" retVal = "text/html" Case "xml" retVal = "text/xml" Case "csv" retVal = "text/plain" Case "tif" retVal = "image/tif" Case "tiff" retVal = "image/tif" Case "gif" retVal = "image/gif" Case "bmp" retVal = "image/bmp" Case "jpg" retVal = "image/jpeg" Case "jpeg" retVal = "image/jpeg" End Select Return retVal End Function