SPFieldLink.DisplayName 属性

获取或设置字段引用的显示名称。

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

语法

声明
Public Property DisplayName As String
    Get
    Set
用法
Dim instance As SPFieldLink
Dim value As String

value = instance.DisplayName

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

属性值

类型:System.String
字段引用的显示名称。

备注

如果DisplayName属性未显式设置,则返回的对象Name属性的值。

DisplayName属性用于目的类似,均由SPField.Title属性。这两个属性提供列的显示名称。例如,网站栏库中列出的列,在列表中的名称将采用的网站的字段集合中每个SPField对象的Title属性。在特定内容类型的网站内容类型页上列出的列,将从内容类型的字段引用集合中每个SPFieldLink对象的DisplayName属性采用名称。

网站栏添加到内容类型后,您可以设置SPFieldLink对象的DisplayName属性值为SPField对象的Title属性值不同的值允许的内容类型使用相同的列定义的不同的显示名称。

示例

下面的示例演示的控制台应用程序创建Company内容类型。新内容类型基于Item内容类型,因为它继承引用网站栏名为"Title"。应用程序更改在Company内容类型从"Title"到"公司"。 此列的显示名称若要验证的内容类型列的显示名称现在是不同的网站栏的显示名称,该应用程序打印到控制台这两个名称。

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

另请参阅

引用

SPFieldLink 类

SPFieldLink 成员

Microsoft.SharePoint 命名空间

其他资源

Fields and Field References

Introduction to Columns

Introduction to Content Types