SPField.ListsFieldUsedIn method

Returns information about the Web sites and lists in which the current field is used.

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

Public Function ListsFieldUsedIn As ICollection(Of SPFieldTemplateUsage)
Dim instance As SPField
Dim returnValue As ICollection(Of SPFieldTemplateUsage)

returnValue = instance.ListsFieldUsedIn()

Return value

Type: System.Collections.Generic.ICollection<SPFieldTemplateUsage>
A collection of SPFieldTemplateUsage objects that contain information about the Web sites and the lists where the field is used.

The following example is a console application that calls the ListsFieldUsedIn method to determine where the Attachments field is used.

Imports System
Imports System.Collections.Generic
Imports Microsoft.SharePoint

Module ConsoleApp

    Sub Main()
        Using site As New SPSite("http://localhost")

            Dim fld As SPField = site.RootWeb.AvailableFields(SPBuiltInFieldId.Attachments)
            Console.WriteLine("The {0} field is used in:" & vbLf, fld.Title)

            Dim collection As ICollection(Of SPFieldTemplateUsage) = fld.ListsFieldUsedIn()
            For Each usage As SPFieldTemplateUsage In collection
                Dim web As SPWeb = site.AllWebs(usage.WebID)
                Dim list As SPList = web.Lists(usage.ListID)
                Console.WriteLine("{0} list in {1}", list.Title, web.Title)


        End Using
        Console.Write(vbCrLf & "Press ENTER to continue....")
    End Sub

End Module