共用方式為


SPFieldLookup.LookupList property

取得或設定此欄位的值來源的清單會識別的 GUID 的字串表示。

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

Syntax

'宣告
Public Property LookupList As String
    Get
    Set
'用途
Dim instance As SPFieldLookup
Dim value As String

value = instance.LookupList

instance.LookupList = value
public string LookupList { get; set; }

Property value

Type: System.String
識別做為來源的欄位的資訊清單的 GUID 的字串表示。如果欄位不是指向清單,則傳回空字串。

Exceptions

Exception Condition
SPException

屬性已設定。設定LookupList屬性之後,您無法變更 [查詢] 清單。

備註

這個屬性會傳回來源清單中的ID屬性的字串表示。當您藉由呼叫AddLookupAddDependentLookup方法的SPFieldCollection物件,表示清單的欄位集合您想要新增為查閱資料行的位置建立SPFieldLookup物件時,會自動設定LookupList屬性。

重要

查閱資料行建立之後,就無法變更目標] 清單中的色彩。

Examples

下列範例會列舉欄位] 清單中,尋找欄位的型別SPFieldLookup相關聯的主控台應用程式。當它找到該類型的欄位時,應用程式會使用LookupList屬性的值來取得所要的查閱欄位點,然後LookupField屬性,以取得目標中的欄位的值清單 [查詢] 欄位所指向的點的清單的參考。

using System;
using Microsoft.SharePoint;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite siteCollection = new SPSite("https://localhost"))
            {
                using (SPWeb site = siteCollection.OpenWeb())
                {
                    SPList list = site.Lists["Pending Orders"];

                    foreach (SPField item in list.Fields)
                    {
                        if (item is SPFieldLookup)
                        {
                            SPFieldLookup field = (SPFieldLookup)item;

                            if (!String.IsNullOrEmpty(field.LookupList) && !String.IsNullOrEmpty(field.LookupField))
                            {
                                // Is this the primary or secondary field for a list relationship?
                                string strRelationship = field.IsRelationship ? "Primary":"Secondary";

                                // Print the display name of the field.
                                Console.WriteLine("\nField: {0} ({1} Field)", field.Title, strRelationship);

                                // Is this a secondary field in a list relationship?
                                if (field.IsDependentLookup)
                                {
                                    SPField primaryField = list.Fields[new Guid(field.PrimaryFieldId)];
                                    Console.WriteLine("Primary Field: {0}", primaryField.Title);
                                }

                                // Get the site where the target list is located.
                                using (SPWeb targetSite = siteCollection.AllWebs[field.LookupWebId])
                                {
                                    // Get the name of the list where this field gets information.
                                    SPList targetList = targetSite.Lists[new Guid(field.LookupList)];
                                    Console.WriteLine("Related list: {0}", targetList.Title);

                                    // Get the name of the field where this field gets information.
                                    SPField targetField = targetList.Fields.GetFieldByInternalName(field.LookupField);
                                    Console.WriteLine("Related field: {0}", targetField.Title);
                                }
                            }
                        }
                    }
                }
            }
            Console.Write("\nPress ENTER to continue...");
            Console.ReadLine();
        }
    }
}
Imports System
Imports Microsoft.SharePoint

Module ConsoleApp

    Sub Main()
        Using siteCollection As New SPSite("https://localhost")
            Using site As SPWeb = siteCollection.OpenWeb()
                Dim list As SPList = site.Lists("Pending Orders")

                For Each item As SPField In list.Fields
                    If TypeOf item Is SPFieldLookup Then
                        Dim field As SPFieldLookup = DirectCast(item, SPFieldLookup)

                        If Not String.IsNullOrEmpty(field.LookupList) AndAlso Not String.IsNullOrEmpty(field.LookupField) Then
                            ' Is this the primary or secondary field for a list relationship?
                            Dim strRelationship As String = If(field.IsRelationship, "Primary", "Secondary")

                            ' Print the display name of the field.
                            Console.WriteLine(vbLf & "Field: {0} ({1} Field)", field.Title, strRelationship)

                            ' Is this a secondary field in a list relationship?
                            If field.IsDependentLookup Then
                                Dim primaryField As SPField = list.Fields(New Guid(field.PrimaryFieldId))
                                Console.WriteLine("Primary Field: {0}", primaryField.Title)
                            End If

                            ' Get the site where the target list is located.
                            Using targetSite As SPWeb = siteCollection.AllWebs(field.LookupWebId)
                                ' Get the name of the list where this field gets information.
                                Dim targetList As SPList = targetSite.Lists(New Guid(field.LookupList))
                                Console.WriteLine("Related list: {0}", targetList.Title)

                                ' Get the name of the field where this field gets information.
                                Dim targetField As SPField = targetList.Fields.GetFieldByInternalName(field.LookupField)
                                Console.WriteLine("Related field: {0}", targetField.Title)
                            End Using
                        End If
                    End If
                Next
            End Using
        End Using
        Console.Write(vbLf & "Press ENTER to continue...")
        Console.ReadLine()
    End Sub
End Module

請參閱

參照

SPFieldLookup class

SPFieldLookup members

Microsoft.SharePoint namespace

LookupField

ID

AddLookup(String, Guid, Boolean)

AddDependentLookup(String, Guid)