Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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)
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class SPHealthReportsList : SPList, 
	IDisposable

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.

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();
        }
    }
}
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.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.