次の方法で共有


SPFarm class

Represents a Microsoft SharePoint Foundation farm.

Inheritance hierarchy

System.Object
  Microsoft.SharePoint.Administration.SPAutoSerializingObject
    Microsoft.SharePoint.Administration.SPPersistedObject
      Microsoft.SharePoint.Administration.SPPersistedUpgradableObject
        Microsoft.SharePoint.Administration.SPFarm

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

Syntax

'Declaration
<UpgradableAttribute> _
<GuidAttribute("674DA553-EA77-44a3-B9F8-3F70D786DE6A")> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public Class SPFarm _
    Inherits SPPersistedUpgradableObject _
    Implements IBackupRestoreConfiguration, IBackupRestore, IMigratable
'Usage
Dim instance As SPFarm
[UpgradableAttribute]
[GuidAttribute("674DA553-EA77-44a3-B9F8-3F70D786DE6A")]
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public class SPFarm : SPPersistedUpgradableObject, IBackupRestoreConfiguration, 
    IBackupRestore, IMigratable

Remarks

The SPFarm object is the top node in the extensible configuration object model, which is designed to interact with the configuration data store. It contains global settings for all the servers, services, and solutions that are installed in a server farm. Use the Servers, Services, or Solutions property to retrieve these collections.

To access the current server farm object, you can use members on SPFarm.Local. For example, to return an SPServiceCollection object that represents the collection of services in the current server farm, use SPFarm.Local.Services. In addition, you can use the Farm property of classes that derive from the SPPersistedObject class, or you can use the Farm property of the SPSolution class, to get the server farm of the current object or solution.

Examples

The following example registers a custom job definition on each Web application within the current server farm.

Dim farm As SPFarm = SPFarm.Local
Dim service As SPWebService = farm.Services.GetValue < SPWebService > ""

Dim webApp As SPWebApplication

For Each webApp In  service.WebApplications
    Dim job As SPJobDefinition

    For Each job In  webApp.JobDefinitions

        If job.Name = "MyCustomJobDefinitionName" Then
            j.Delete()
        End If
    Next job

    Dim newJob As New MyCustomJobDefinition("MyCustomJobDefinitionName", webApp)
    Dim schedule As SPSchedule = SPSchedule.FromString("every 5 minutes between 0 and 59")
    newJob.Schedule = schedule

    newJob.Update()
Next webApp
SPFarm farm = SPFarm.Local;
SPWebService service = farm.Services.GetValue<SPWebService>("");

foreach (SPWebApplication webApp in service.WebApplications)
{
    foreach (SPJobDefinition job in webApp.JobDefinitions)
    {
        if (job.Name == "MyCustomJobDefinitionName")
        {
            j.Delete();
        }
    }

    MyCustomJobDefinition newJob = new 
        MyCustomJobDefinition("MyCustomJobDefinitionName", webApp);
    SPSchedule schedule = SPSchedule.FromString("every 5 minutes between 0 and 59");
    newJob.Schedule = schedule;

    newJob.Update();
}

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

SPFarm members

Microsoft.SharePoint.Administration namespace