SPHealthRulesList Class
Represents a list of SharePoint Health Analyzer rule definitions registered with the farm.
Inheritance Hierarchy
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)
Syntax
'Declaration
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public NotInheritable Class SPHealthRulesList _
Inherits SPList _
Implements IDisposable
'Usage
Dim instance As SPHealthRulesList
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class SPHealthRulesList : SPList,
IDisposable
Remarks
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
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.
Examples
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();
}
}
}
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 SPHealthRulesList = SPHealthRulesList.Local
' Get a collection of rule definitions in alphabetical order.
Dim query As SPQuery = New SPQuery()
query.Query = "<OrderBy><FieldRef Name='LinkTitleNoMenu' /></OrderBy>"
Dim rules As SPListItemCollection = list.GetItems(query)
' Print the title, date, and status for each item.
Dim rule As SPListItem
For Each rule In rules
Console.WriteLine(vbCrLf + "{0} Runs: {1}", _
rule(SPBuiltInFieldId.LinkTitleNoMenu).ToString(), _
rule(SPBuiltInFieldId.HealthRuleSchedule).ToString())
Next
End Using
End If
Console.Write(vbCrLf + "Press ENTER to continue...")
Console.Read()
End Sub
End Module
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
Microsoft.SharePoint.Administration.Health Namespace