SPFieldLinkCollection.Item Property (String)
Gets the specified SPFieldLink object from the collection by indexing on the object name.
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 ( _
name As String _
) As SPFieldLink
Get
'Usage
Dim instance As SPFieldLinkCollection
Dim name As String
Dim value As SPFieldLink
value = instance.Item(name)
public SPFieldLink this[
string name
] { get; }
Parameters
name
Type: System.StringThe name of the field reference.
Property Value
Type: Microsoft.SharePoint.SPFieldLink
An SPFieldLink object.
Remarks
The name that you pass as an argument can be expressed either as the value of the Name property or the value of the DisplayName property. When you pass the value of the Name property, you often get more reliable results, for two reasons. First, no two objects in the collection can have the same value in the Name property, whereas two or more objects can have the same value in the DisplayName property. Second, the Name property is read-only and therefore its value is immutable, whereas the DisplayName property can be modified by users with sufficient rights.
If the specified object is not found, the indexer returns null.
Examples
The following example shows a console application that iterates through all content types available at the site level, looking for references to a particular site column. In particular, the application searches on “WorkPhone,” the internal name of the site column, rather than using the column’s display name, “Business Phone.”
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"
Dim cts As SPContentTypeCollection = web.AvailableContentTypes
Dim fldLnk As SPFieldLink = Nothing
For Each ct As SPContentType In cts
fldLnk = ct.FieldLinks(fldName)
If fldLnk IsNot Nothing Then
Console.WriteLine("Content type {0} links to the {1} field", _
ct.Name, fldName)
End If
Next ct
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";
SPContentTypeCollection cts = web.AvailableContentTypes;
SPFieldLink fldLnk = null;
foreach (SPContentType ct in cts)
{
fldLnk = ct.FieldLinks[fldName];
if (fldLnk != null)
{
Console.WriteLine("Content type {0} links to the {1} field", ct.Name, fldName);
}
}
}
}
Console.Write("Press ENTER to continue...");
Console.ReadLine();
}
}
}
See Also
Reference
Microsoft.SharePoint Namespace