SPHealthReportsList class

Represents a list of SharePoint Health Analyzer reports.

Inheritance hierarchy

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)

Syntax

'Declaration
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public NotInheritable Class SPHealthReportsList _
    Inherits SPList _
    Implements IDisposable
'Usage
Dim instance As SPHealthReportsList
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class SPHealthReportsList : SPList, 
    IDisposable

Remarks

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

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.

Examples

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.

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Administration.Health;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            if (SPFarm.Joined)
            {
                using (SPHealthReportsList list = SPHealthReportsList.Local)
                {
                    // Get a collection of health reports in date order.
                    SPQuery query = new SPQuery();
                    query.Query = "<OrderBy><FieldRef Name=\"Created\" /></OrderBy>";
                    SPListItemCollection reports = list.GetItems(query);

                    // Print the title, date, and status for each item.
                    foreach (SPListItem report in reports)
                    {
                        Console.WriteLine("\n\n{0} \nReport Date: {1} \nStatus: {2}",
                            report[SPBuiltInFieldId.LinkTitleNoMenu].ToString(),
                            report[SPBuiltInFieldId.Created].ToString(),
                            report[SPBuiltInFieldId.HealthReportSeverity].ToString());
                    }
                }
            }
            Console.Write("\nPress ENTER to continue...");
            Console.Read();
        }
    }
}
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

Note

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.

Thread safety

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

See also

Reference

SPHealthReportsList members

Microsoft.SharePoint.Administration.Health namespace

SPHealthRulesList

Other resources

Working with SharePoint Maintenance Manager