Share via


SPFieldLink.Id Property

Gets the GUID that identifies the field reference.

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

Syntax

'Declaration
<ClientCallableConstraintAttribute(Type := ClientCallableConstraintType.NotEmpty)> _
<ClientCallableAttribute> _
Public ReadOnly Property Id As Guid
    Get
'Usage
Dim instance As SPFieldLink
Dim value As Guid

value = instance.Id
[ClientCallableConstraintAttribute(Type = ClientCallableConstraintType.NotEmpty)]
[ClientCallableAttribute]
public Guid Id { get; }

Property Value

Type: System.Guid
A unique identifier for the field reference.

Remarks

The value of this property is identical to the value of the Id property of the field that corresponds to the field reference. You can use the property value as an index into the content type’s SPFieldCollection property as well as its SPFieldLinkCollection property.

Examples

The following example shows a console application that iterates through the SPFieldCollection of a content type and prints the value of the SPField.Id property and the value of the corresponding SPFieldLink.Id property to the console.

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 contentType As SPContentType = web.ContentTypes("Item")
                For Each field As SPField In contentType.Fields
                    Dim link As SPFieldLink = contentType.FieldLinks(field.Id)
                    Console.WriteLine("Field.Id = {0}", field.Id)
                    Console.WriteLine("FieldLink.Id = {0}", link.Id)
                    Console.WriteLine()
                Next field
            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())
                {
                    SPContentType contentType = web.ContentTypes["Item"];
                    foreach (SPField field in contentType.Fields)
                    {
                        SPFieldLink link = contentType.FieldLinks[field.Id];
                        Console.WriteLine("SPField.Id = {0}", field.Id);
                        Console.WriteLine("SPFieldLink.Id = {0}", link.Id);
                        Console.WriteLine();
                    }
                }
            }
            Console.Write("Press ENTER to continue...");
            Console.ReadLine();
        }
    }
}

The application prints the following output to the console.

Field.Id = c042a256-787d-4a6f-8a8a-cf6ab767f12d
FieldLink.Id = c042a256-787d-4a6f-8a8a-cf6ab767f12d

Field.Id = fa564e0f-0c70-4ab9-b863-0177e6ddd247
FieldLink.Id = fa564e0f-0c70-4ab9-b863-0177e6ddd247

Press ENTER to continue...

See Also

Reference

SPFieldLink Class

SPFieldLink Members

Microsoft.SharePoint Namespace

Other Resources

Fields and Field References

Introduction to Columns

Introduction to Content Types