SPHealthReportsList.Local Property

Gets an SPHealthReportsList object that represents the SharePoint Health Analyzer Reports list for the farm.

Namespace:  Microsoft.SharePoint.Administration.Health
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

'Declaration
Public Shared ReadOnly Property Local As SPHealthReportsList
	Get
'Usage
Dim value As SPHealthReportsList

value = SPHealthReportsList.Local

Property Value

Type: Microsoft.SharePoint.Administration.Health.SPHealthReportsList
An SPHealthReportsList object that represents the SharePoint Health Analyzer Reports list for the farm.

ExceptionCondition
InvalidOperationException

The local server is not joined to the farm.

The SPHealthReportsList object returned by the Local property uses unmanaged resources. You are responsible for releasing those resources. One way to do that is to call the Dispose() method when you no longer need the SPHealthReportsList object.

The following example is a console application that queries the health reports list for information about health checks that have failed.

Imports System
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Administration.Health

Module Test

    Sub Main()

        Using reportsList As SPHealthReportsList = SPHealthReportsList.Local

            If Not reportsList Is Nothing Then

                ' Write a query against the list.
                Dim query As SPQuery = New SPQuery()
                query.Query = "<GroupBy>" + _
                                    "<FieldRef Name='HealthReportCategory' Ascending='FALSE'/>" + _
                                "</GroupBy>" + _
                                "<OrderBy>" + _
                                    "<FieldRef Name='HealthReportSeverity' />" + _
                                "</OrderBy>" + _
                                "<Where>" + _
                                    "<Neq>" + _
                                        "<FieldRef Name='HealthReportSeverity' />" + _
                                        "<Value Type='Text'>4 - Success</Value>" + _
                                    "</Neq>" + _
                                "</Where>"

                ' Retrieve list items that satisfy the query.
                Dim reports As SPListItemCollection = reportsList.GetItems(query)

                ' Print information from each item.
                Dim category As String = String.Empty
                Dim report As SPListItem
                For Each report In reports

                    Dim thisCategory As String = report(SPBuiltInFieldId.HealthReportCategory).ToString()
                    If thisCategory <> category Then
                        category = thisCategory
                        Console.WriteLine(vbCrLf + "Category: {0}", category)
                    End If

                    Dim title As String = report(SPBuiltInFieldId.LinkTitleNoMenu).ToString()
                    Dim errorLevel As String = report(SPBuiltInFieldId.HealthReportSeverity).ToString()

                    Console.WriteLine(vbCrLf + "- {0}", title)
                    Console.WriteLine("  Severity: {0}", errorLevel)

                    Dim failingServers As Object = report(SPBuiltInFieldId.HealthReportServers)
                    Dim failingServices As Object = report(SPBuiltInFieldId.HealthReportServices)

                    If Not failingServers Is Nothing Then
                        Console.WriteLine("  Failing servers: {0}", failingServers.ToString())
                    End If
                    If Not failingServices Is Nothing Then
                        Console.WriteLine("  Failing services: {0}", failingServices.ToString())
                    End If

                Next
            End If

        End Using
        Console.Write(vbCrLf + "Press ENTER to continue...")
        Console.Read()
    End Sub

End Module
Show: