SPFieldLookup.LookupList - Propriété

Obtient ou définit la représentation sous forme de chaîne du GUID qui identifie la liste qui est la source de la valeur de ce champ.

Espace de noms :  Microsoft.SharePoint
Assembly :  Microsoft.SharePoint (dans Microsoft.SharePoint.dll)

Syntaxe

'Déclaration
Public Property LookupList As String
    Get
    Set
'Utilisation
Dim instance As SPFieldLookup
Dim value As String

value = instance.LookupList

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

Valeur de propriété

Type : System.String
La représentation sous forme de chaîne du GUID qui identifie la liste qui est la source de données pour le champ. Une chaîne vide est retournée si le champ ne pointe pas vers une liste.

Exceptions

Exception Condition
SPException

La propriété a déjà été définie. Vous ne pouvez pas modifier la liste de recherche une fois que la propriété LookupList est définie.

Remarques

Cette propriété retourne la représentation sous forme de chaîne de la propriété ID de la liste source. La propriété LookupList est définie automatiquement lorsque vous créez un objet SPFieldLookup en appelant la méthode AddLookup ou AddDependentLookup de l'objet SPFieldCollection qui représente la collection de champs pour la liste dans laquelle vous souhaitez ajouter la colonne de recherche.

Important

Une fois qu'une colonne de recherche est établie, la liste cible ne peut pas être modifiée.

Exemples

L'exemple suivant est une application console qui énumère les champs associés à une liste, à la recherche pour les champs de type SPFieldLookup. Lorsqu'il trouve un champ de ce type, l'application utilise la valeur de la propriété LookupList pour obtenir une référence à la liste répertoriant les points de champ liste de choix, puis la valeur de la propriété LookupField pour obtenir le champ de la cible que le champ de recherche pointant vers.

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

Voir aussi

Référence

SPFieldLookup classe

SPFieldLookup - Membres

Microsoft.SharePoint - Espace de noms

LookupField

ID

AddLookup(String, Guid, Boolean)

AddDependentLookup(String, Guid)