Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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)
Available in Sandboxed Solutions: No
Available in SharePoint Online

[SubsetCallableExcludeMemberAttribute(SubsetCallableExcludeMemberType.UnsupportedSPType)]
public ICollection<SPFieldTemplateUsage> 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.

using System;
using System.Collections.Generic;
using Microsoft.SharePoint;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://localhost"))
            {
                SPField fld = site.RootWeb.AvailableFields[SPBuiltInFieldId.Attachments];
                Console.WriteLine("The {0} field is used in:\n", fld.Title);

                ICollection<SPFieldTemplateUsage> collection = fld.ListsFieldUsedIn();
                foreach (SPFieldTemplateUsage usage in collection)
                {
                    SPWeb web = site.AllWebs[usage.WebID];
                    SPList list = web.Lists[usage.ListID];
                    Console.WriteLine("{0} list in {1}", list.Title, web.Title);

                    web.Dispose();
                }
            }
            Console.Write("\nPress ENTER to continue....");
            Console.Read();
        }
    }
}
Show:
© 2015 Microsoft