SPFieldLink.DisplayName Property

Gets or sets the display name for the field reference.

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

Syntax

'Declaration
Public Property DisplayName As String
    Get
    Set
'Usage
Dim instance As SPFieldLink
Dim value As String

value = instance.DisplayName

instance.DisplayName = value
public string DisplayName { get; set; }

Property Value

Type: System.String
The display name of the field reference.

Remarks

If the DisplayName property has not been explicitly set, it returns the value of the object’s Name property.

The DisplayName property serves a purpose similar to that served by the SPField.Title property. Both properties provide a display name for a column. For example, when columns are listed in the Site Column Gallery, the names in the list are taken from the Title property for each SPField object in the site’s field collection. When columns are listed on the Site Content Type page for a particular content type, the names are taken from the DisplayName property of each SPFieldLink object in the field reference collection of the content type.

When you add a site column to a content type, you can set the DisplayName property value of the SPFieldLink object to a value that is different from the Title property value of the SPField object, allowing the content type to use a different display name for the same column definition.

Examples

The following example shows a console application that creates a Company content type. Because the new content type is based on the Item content type, it inherits a reference to a site column named “Title.” The application changes the display name of this column in the Company content type from “Title” to “Company.” To verify that the display name of the content type column is now different from the display name of the site column, the application prints both names 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
                ' Create a new content type.
                Dim companyType As New SPContentType(web.AvailableContentTypes("Item"), _
                                                     web.ContentTypes, "Company")
                web.ContentTypes.Add(companyType)

                ' Get the site field named Title.
                Dim field As SPField = web.Fields("Title")

                ' Get the same field in the content type.
                Dim fieldLink As SPFieldLink = companyType.FieldLinks(field.Id)

                ' Change the display name from Title to Company.
                fieldLink.DisplayName = "Company"
                companyType.Update()

                ' Verify our work.
                Console.WriteLine("The display name of the site column is {0}.", field.Title)
                Console.WriteLine("The display name of the content type column is {0}.", fieldLink.DisplayName)

            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())
                {   
                    // Create a new content type.
                    SPContentType companyType = new SPContentType(web.AvailableContentTypes["Item"],
                                                                  web.ContentTypes, "Company");
                    web.ContentTypes.Add(companyType);

                    // Get the site field named Title.
                    SPField field = web.Fields["Title"];

                    // Get the same field in the content type.
                    SPFieldLink fieldLink = companyType.FieldLinks[field.Id];

                    // Change the display name from Title to Company.
                    fieldLink.DisplayName = "Company";
                    companyType.Update();

                    // Verify our work.
                    Console.WriteLine("The display name of the site column is {0}.", field.Title);
                    Console.WriteLine("The display name of the content type column is {0}.", fieldLink.DisplayName);
                }
            }
            Console.Write("Press ENTER to continue...");
            Console.ReadLine();
        }
    }
}

The application prints the following output to the console.

The display name of the site column is Title.
The display name of the content type column is Company.
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