当前位置 : 主页 > 编程语言 > c语言 >

vb.net – 使用命令行跨子文件夹删除多个SSRS报告?

来源:互联网 收集:自由互联 发布时间:2021-06-24
我是SSRS部署的新手,我一直在寻找,但无法找到适用于我的情况的确切方案.我在SSRS 2012中的不同子文件夹中部署了多个报告.例如: 销售/销售报告1 销售/销售报告2 财务/ finReport1 财务/
我是SSRS部署的新手,我一直在寻找,但无法找到适用于我的情况的确切方案.我在SSRS 2012中的不同子文件夹中部署了多个报告.例如:

>销售/销售报告1
>销售/销售报告2
>财务/ finReport1
>财务/ finReport2
> Misc / miscReport1
> Misc / miscReport2

由于有时SSRS不喜欢覆盖的报告文件,我想在部署任何新报告之前删除实例中的所有报告文件.我可以通过使用rs.exe调用此脚本来成功删除文件夹及其内容:

Public Sub Main()  

  rs.Credentials = System.Net.CredentialCache.DefaultCredentials  

  Dim bh As New BatchHeader()  

  bh.BatchID = rs.CreateBatch()  

  rs.BatchHeaderValue = bh 

   'Delete all reports from Main Folder and sub folders.Note:The Folders will be deleted also.  
   'If do not want to delete the folder, we could use rs.CreateFolder(“Folder name”, “/Main     Folder”, “nothing”) to create a new one with nothing.  

 rs.DeleteItem("/Sales")
 rs.DeleteItem("/Finance")
 rs.DeleteItem("/Misc") 

   'Delete all reports from a sub folder, and delete the sub folder  
   'rs.DeleteItem("/Main Folder/Sub Folder ")  

  rs.BatchHeaderValue = bh       

  ' Delete folders using batch header.  

  Try  

     rs.ExecuteBatch()  
     Console.WriteLine("Folders deleted successfully.")  

  Catch e As SoapException  
     Console.WriteLine(e.Detail.InnerXml.ToString())  

  Finally  
      rs.BatchHeaderValue = Nothing 

  End Try  

End Sub 'Main

问题在于如果这些文件夹中的任何一个不存在,脚本将停止.我正在努力确定解决这个问题的最佳方法.最好的方法是清空文件夹并将它们留在那里,或找到一种方法来忽略错误并继续?

根据答案,我将如何在此脚本中调用它?

您可以通过运行父文件夹中的项目并查找具有预期名称的任何子文件夹来检查文件夹是否存在.然后,仅当存在时,尝试删除该文件夹.

这应该可以解决您的问题,即您只有在知道它存在时才会删除.

您的代码可能类似于:

Public Sub Main()

    rs.Credentials = System.Net.CredentialCache.DefaultCredentials

    DeleteFolder("Sales")
    DeleteFolder("Finance")

End Sub

Public Sub DeleteFolder(ByVal folderName As String)

    Dim items() as CatalogItem  
    Dim item As CatalogItem
    Dim folderExists As Boolean = False

    items = rs.ListChildren("/", False)

    For Each item In items

        If item.TypeName = "Folder" And item.Name.Equals(folderName)

            folderExists = True

        End If

    Next

    If folderExists

        Try

            rs.DeleteItem("/" + folderName)
            Console.WriteLine("Deleted folder {0}", folderName)

        Catch e As Exception

            Console.WriteLine(e.Message)

        End Try     

    Else

        Console.WriteLine("Folder {0} does not exist", folderName)

    End If

End Sub

这只会检查/文件夹 – 您可能需要调整以匹配您的设置.

网友评论