Tuesday, September 3, 2013

How to get search content sources in a sharepoint site

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim farmServices As SPServiceCollection = SPFarm.Local.Services
        For Each s As SPService In farmServices
            Dim x As SPServiceApplicationCollection = s.Applications
            For Each f As SPServiceApplication In x
                If f.TypeName = "Search Service Application" Then
                    If f.DisplayName = "FAST Content SSA 14012013" Then
                        Dim ssa As SearchServiceApplication = CType(f, SearchServiceApplication)
                        Dim consources As List(Of String) = ssa.GetContentSourceNames()
                        For i As Integer = 0 To consources.Count - 1
                            Label1.Text &= consources(i) + "</br>"
                        Next
                    End If
                End If

            Next

        Next
    End Sub

No comments:

Post a Comment