다음을 통해 공유


SPFieldLinkCollection.Item Property (Guid)

Gets the specified SPFieldLink object from the collection by using its identifier (ID).

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
Public ReadOnly Property Item ( _
    id As Guid _
) As SPFieldLink
    Get
'Usage
Dim instance As SPFieldLinkCollection
Dim id As Guid
Dim value As SPFieldLink

value = instance.Item(id)
public SPFieldLink this[
    Guid id
] { get; }

Parameters

  • id
    Type: System.Guid

    The value of the Id property of the SPFieldLink object to retrieve.

Property Value

Type: Microsoft.SharePoint.SPFieldLink
An SPFieldLink object.

Remarks

If the specified object is not found, the indexer returns null.

Examples

The following example shows a console application that iterates through content types that are available at the site level, looking for references to a particular site column.

Imports System
Imports Microsoft.SharePoint

Module ConsoleApp
    Sub Main()
        Dim site As SPSite = New SPSite("https://localhost")
        Try
            Dim web As SPWeb = site.OpenWeb()
            Try
                Dim fldName As String = "WorkPhone"
                Try
                    Dim fld As SPField = web.Fields.GetField(fldName) 'Throws exception if field not found
                    For Each ct As SPContentType In web.AvailableContentTypes
                        Dim fldLnk As SPFieldLink = ct.FieldLinks(fld.Id)
                        If fldLnk IsNot Nothing Then
                            Console.WriteLine("Content type {0} links to the {1} field.", _
                                              ct.Name, fldName)
                        End If
                    Next ct
                Catch ex As ArgumentException
                    Console.WriteLine("ArgumentException thrown by {0}.", ex.TargetSite)
                    Console.WriteLine("Argument passed to GetField is '{0}'.", fldName)
                End Try
            Finally
                web.Dispose()
            End Try
            Finally
                site.Dispose()
            End Try
        Console.Write("Press ENTER to continue...")
        Console.ReadLine()
    End Sub
End Module
using System;
using Microsoft.SharePoint;

namespace Test
{
    class ConsoleApp
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("https://localhost"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    string fldName = "WorkPhone";
                    try
                    {
                        SPField fld = web.Fields.GetField(fldName); // Throws exception if field not found
                        foreach (SPContentType ct in web.AvailableContentTypes)
                        {
                            SPFieldLink fldLnk = ct.FieldLinks[fld.Id];
                            if (fldLnk != null)
                            {
                                Console.WriteLine("Content type {0} links to the {1} field.",
                                                  ct.Name, fldName);
                            }
                        }
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine("ArgumentException thrown by {0}.", ex.TargetSite);
                        Console.WriteLine("Argument passed to GetField is '{0}'.", fldName);
                    }
                }
            }
            Console.Write("Press ENTER to continue...");
            Console.ReadLine();
        }
    }
}

See Also

Reference

SPFieldLinkCollection Class

SPFieldLinkCollection Members

Item Overload

Microsoft.SharePoint Namespace

SPFieldLink

SPContentType

Other Resources

Fields and Field References

Introduction to Columns