SPFieldLookup.LookupWebId property

Gets or sets the ID of the Web site that contains the list that is the source of this field's value.

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

Public Property LookupWebId As Guid
Dim instance As SPFieldLookup
Dim value As Guid

value = instance.LookupWebId

instance.LookupWebId = value

Property value

Type: System.Guid
The value of the ID property for the Web site.


The list that the field belongs to is an external list


Once set, the value of the property cannot be changed.

You must have SPBasePermissions.Open permissions to set this property.

The following example is a console application that queries a list's collection of fields for lookup fields. For each lookup field that is found, the application prints the name of the field, the title of the list that the lookup field points to, the field in the target list that is the source of the lookup field's value, and the name of the Web site where the source list is located.

Imports System
Imports Microsoft.SharePoint

Module ConsoleApp

    Sub Main()
        Using siteCollection As New SPSite("http://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
            End Using
        End Using
        Console.Write(vbLf & "Press ENTER to continue...")
    End Sub
End Module