Export (0) Print
Expand All

SPHealthRulesList Class

Represents a list of SharePoint Health Analyzer rule definitions registered with the farm.

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

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

[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class SPHealthRulesList : SPList, 
	IDisposable

This class represents the Health Rules list in the Monitoring section of Central Administration. A farm administrator can use the Health Rules list to edit the settings for a health rule, changing where or when the rule runs, or even disabling the rule altogether.

To get an instance of the SPHealthRulesList class, access the static Local property. Once you have SPHealthRulesList object, you can query the list as you would any SPList object.

Important noteImportant

The SPHealthRulesList 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 console application that prints the title and schedule for every rule in the Health Rules list for the farm. Note that in order to access the Health Rules 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 (SPHealthRulesList list = SPHealthRulesList.Local)
                {
                    // Get a collection of rule definitions in alphabetical order.
                    SPQuery query = new SPQuery();
                    query.Query = "<OrderBy><FieldRef Name=\"LinkTitleNoMenu\" /></OrderBy>";
                    SPListItemCollection rules = list.GetItems(query);

                    // Print the title and schedule for each item.
                    foreach (SPListItem rule in rules)
                    {
                        Console.WriteLine("\n{0} Runs: {1}",
                            rule[SPBuiltInFieldId.LinkTitleNoMenu].ToString(),
                            rule[SPBuiltInFieldId.HealthRuleSchedule].ToString());
                    }
                }
            }
            Console.Write("\nPress ENTER to continue...");
            Console.Read();
        }
    }
}

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

Community Additions

ADD
Show:
© 2014 Microsoft