共用方式為


SPFarm class

代表Microsoft SharePoint Foundation伺服器陣列。

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

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

備註

SPFarm物件是可延伸的組態物件模型的設計目的是互動之設定資料存放區中最頂端的節點。包含所有的伺服器、 服務及解決方案的已安裝在伺服器陣列中的全域設定。使用ServersServicesSolutions屬性來擷取這些集合。

若要存取目前的伺服器陣列物件,您可以使用SPFarm.Local上的成員。例如,若要傳回SPServiceCollection物件,代表目前的伺服器陣列中的服務的集合,請使用SPFarm.Local.Services。此外,您可以使用衍生自SPPersistedObject類別的類別的Farm屬性,或您可以使用FarmSPSolution類別屬性,來取得目前的物件或解決方案的伺服器陣列。

Examples

下列範例會登錄在目前的伺服器陣列內的每個 Web 應用程式的自訂工作定義。

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.

請參閱

參照

SPFarm members

Microsoft.SharePoint.Administration namespace