Export (0) Print
Expand All

SPHealthRulesList.Local Property

Gets an SPHealthRulesList object that represents the SharePoint Health Analyzer Rules list for the farm.

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

public static SPHealthRulesList Local { get; }

Property Value

Type: Microsoft.SharePoint.Administration.Health.SPHealthRulesList
An SPHealthRulesList object that represents the SharePoint Health Analyzer Rules list for the farm.

ExceptionCondition
InvalidOperationException

The local server is not joined to the farm.

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

The following example is a console application that queries the Health Rules list for rules that are capable of automatically repairing the problem that the rule is designed to detect. The example enumerates the result set, printing the display text and schedule for each rule to the console.

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

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPHealthRulesList definitions = SPHealthRulesList.Local)
            {
                if (definitions != null)
                {
                    // Write a query to find auto-repair rules.
                    SPQuery query = new SPQuery();
                    query.Query =  "<Where><Eq>";
                    query.Query += "<FieldRef Name=\"HealthRuleAutoRepairEnabled\" />";
                    query.Query += "<Value Type=\"Boolean\">1</Value>";
                    query.Query += "</Eq></Where>";

                    // Retrieve list items that satisfy the query.
                    SPListItemCollection rules = definitions.GetItems(query);

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