Export (0) Print
Expand All

SPHealthReportsList Class

Represents a list of SharePoint Health Analyzer reports.

System.Object
  Microsoft.SharePoint.SPSecurableObject
    Microsoft.SharePoint.SPList
      Microsoft.SharePoint.Administration.Health.SPHealthReportsList

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

'Declaration
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
PublicNotInheritableClassSPHealthReportsList _
	InheritsSPList _
	ImplementsIDisposable
'Usage
DiminstanceAsSPHealthReportsList

This class represents the Health Reports list in the Monitoring section of Central Administration. When a health rule executes, SharePoint Health Analyzer creates a status report and adds it to the Health Reports list. The default view on this list displays only items that failed the most recent health check.

You can access the Health Reports list through the static Local property. Once you have an instance of the SPHealthReportsList class, you can query the list as you would any SPList object.

Important noteImportant

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 object.

The following example is a simple console application that prints the title, date, and status of each report in the Health Reports list for the farm. Note that in order to access the Health Reports list, the local server must be joined to the farm.

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

Module Test

    Sub Main()

        If SPFarm.Joined Then

            Using list As SPHealthReportsList = SPHealthReportsList.Local

                ' Get a collection of health reports in date order.
                Dim query As SPQuery = New SPQuery()
                query.Query = "<OrderBy><FieldRef Name='Created' /></OrderBy>"
                Dim reports As SPListItemCollection = list.GetItems(query)

                ' Print the title, date, and status for each item.
                Dim report As SPListItem
                For Each report In reports
                    Console.WriteLine(vbCrLf + vbCrLf + _
                                      report(SPBuiltInFieldId.LinkTitleNoMenu).ToString())
                    Console.WriteLine("Report Date: {0}", _
                                      report(SPBuiltInFieldId.Created).ToString())
                    Console.WriteLine("Status: {0}", _
                                      report(SPBuiltInFieldId.HealthReportSeverity).ToString())
                Next

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

End Module
NoteNote

For information about how to use Language-Integrated Query (LINQ) queries to retrieve list items in SharePoint Foundation, see Managing Data with LINQ to SharePoint.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft