共用方式為


SPFieldCollection.AddLookup method (String, Guid, Guid, Boolean)

建立查閱欄位的一份清單的欄位集合中該點來在另一個清單中不同的網站集合中的欄位。

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

Syntax

'宣告
Public Function AddLookup ( _
    displayName As String, _
    lookupListId As Guid, _
    lookupWebId As Guid, _
    bRequired As Boolean _
) As String
'用途
Dim instance As SPFieldCollection
Dim displayName As String
Dim lookupListId As Guid
Dim lookupWebId As Guid
Dim bRequired As Boolean
Dim returnValue As String

returnValue = instance.AddLookup(displayName, _
    lookupListId, lookupWebId, bRequired)
public string AddLookup(
    string displayName,
    Guid lookupListId,
    Guid lookupWebId,
    bool bRequired
)

參數

  • displayName
    Type: System.String

    字串,指定欄位的顯示名稱。

  • lookupListId
    Type: System.Guid

    System.Guid物件,指定查閱欄位的目標清單。

  • lookupWebId
    Type: System.Guid

    System.Guid指定的物件,[查詢] 欄位的目標網站。

  • bRequired
    Type: System.Boolean

    true 如果欄位必須包含值 ;否則, false.

傳回值

Type: System.String
字串,包含用於欄位的內部名稱。您可以將這個值傳遞至GetFieldByInternalName(String)方法來擷取新的欄位。會傳回該欄位為的型別SPFieldLookup

備註

這個方法會建立目前清單的欄位集合中的型別SPFieldLookup欄位。一個清單中的查閱欄位接受它的值從另一個清單中的欄位在lookupListId參數中指定的目標清單。集合中加入 [查詢] 欄位之後,您應該從集合中擷取,並設定LookupField屬性,以識別在 [目標] 清單中的 [來源] 欄位。

[查詢] 欄位值的來源的目標清單所知的 [查詢] 欄位中 ;也就是您可以藉由檢查目標清單的GetRelatedFields()方法所傳回集合中的物件會發現 [查詢] 欄位。

目前的使用者必須具有SPBasePermissions。當您呼叫這個方法中的 [目標] 清單上的ManageLists使用權限。

請參閱

參照

SPFieldCollection class

SPFieldCollection members

AddLookup overload

Microsoft.SharePoint namespace

SPFieldLookup

LookupField

GetFieldByInternalName(String)

AddDependentLookup(String, Guid)

GetRelatedFields()