SPField.ListsFieldUsedIn 方法

返回有关当前字段在其中使用网站和列表的信息。

命名空间:  Microsoft.SharePoint
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
Public Function ListsFieldUsedIn As ICollection(Of SPFieldTemplateUsage)
用法
Dim instance As SPField
Dim returnValue As ICollection(Of SPFieldTemplateUsage)

returnValue = instance.ListsFieldUsedIn()
public ICollection<SPFieldTemplateUsage> ListsFieldUsedIn()

返回值

类型:System.Collections.Generic.ICollection<SPFieldTemplateUsage>
包含有关网站和列表时使用此字段的信息的SPFieldTemplateUsage对象的集合。

示例

下面的示例是调用ListsFieldUsedIn方法来确定使用 Attachments 字段是一个控制台应用程序。

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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("https://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();
        }
    }
}
Imports System
Imports System.Collections.Generic
Imports Microsoft.SharePoint

Module ConsoleApp

    Sub Main()
        Using site As New SPSite("https://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)

                web.Dispose()
            Next

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

End Module

另请参阅

引用

SPField 类

SPField 成员

Microsoft.SharePoint 命名空间