共用方式為


SPFieldLookup.LookupWebId property

對於包含的清單是此欄位值來源的網站,取得或設定識別碼。

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

Syntax

'宣告
Public Property LookupWebId As Guid
    Get
    Set
'用途
Dim instance As SPFieldLookup
Dim value As Guid

value = instance.LookupWebId

instance.LookupWebId = value
public Guid LookupWebId { get; set; }

Property value

Type: System.Guid
Web 站台的ID屬性的值。

Exceptions

Exception Condition
NotSupportedException

欄位所屬的清單是外部的清單

SPException

設定之後,無法變更屬性的值。

備註

您必須SPBasePermissions。若要設定這個屬性的Open權限。

Examples

下列範例是一個主控台應用程式,查詢欄位的查閱欄位清單的集合。找不到每個 [查詢] 欄位中,應用程式是列印的欄位名稱,要的查閱欄位點,在目標中的欄位清單也就是 [查詢] 欄位值的來源和 Web 站台名稱清單的標題來源] 清單中的色彩所在的位置。

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["Completed 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

LookupList

LookupField