SPFieldLookup.LookupList 属性

获取或设置标识此字段的值的源的列表的 GUID 的字符串表示形式。

命名空间:  Microsoft.SharePoint
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
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; }

属性值

类型:System.String
标识的字段的信息的源的列表的 GUID 的字符串表示形式。如果字段中未指向列表,则返回空字符串。

异常

异常 条件
SPException

已设置该属性。LookupList属性设置后,您无法更改查阅列表。

备注

此属性返回的字符串表示形式的源列表中的ID属性。当您创建一个SPFieldLookup对象通过调用AddLookupAddDependentLookupSPFieldCollection对象列表的字段集合表示您要在其中添加查阅列时,将自动设置LookupList属性。

重要信息注释重要信息

一旦建立查阅列,则不能更改目标列表。

示例

下面的示例是一个控制台应用程序枚举列表,查找类型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 类

SPFieldLookup 成员

Microsoft.SharePoint 命名空间

LookupField

ID

AddLookup(String, Guid, Boolean)

AddDependentLookup(String, Guid)