다음을 통해 공유


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)

Syntax

'Declaration
Public Shared ReadOnly Property Local As SPHealthRulesList
    Get
'Usage
Dim value As SPHealthRulesList

value = SPHealthRulesList.Local
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.

Exceptions

Exception Condition
InvalidOperationException

The local server is not joined to the farm.

Remarks

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.

Examples

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();
        }
    }
}
Imports System
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Administration.Health

Module Test

    Sub Main()

        Using definitions As SPHealthRulesList = SPHealthRulesList.Local
            If Not definitions Is Nothing Then

                ' Write a query to find auto-repair rules.
                Dim query As SPQuery = 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.
                Dim rules As SPListItemCollection = definitions.GetItems(query)

                ' Print the title and schedule for each item.
                Dim rule As SPListItem
                For Each rule In rules
                    Console.WriteLine("{0,-70} {1}", _
                        rule(SPBuiltInFieldId.LinkTitleNoMenu).ToString(), _
                        rule(SPBuiltInFieldId.HealthRuleSchedule).ToString())
                Next

            End If
        End Using
        Console.Write(vbCrLf + "Press ENTER to continue...")
        Console.Read()
    End Sub

End Module

See Also

Reference

SPHealthRulesList Class

SPHealthRulesList Members

Microsoft.SharePoint.Administration.Health Namespace