SPFieldLink.DisplayName property
取得或設定欄位參照的顯示名稱。
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
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; }
Property value
Type: System.String
顯示參照的名稱] 欄位。
備註
如果未明確設定DisplayName屬性,則會傳回物件的Name屬性的值。
DisplayName屬性會提供類似SPField.Title屬性表所服務的用途。這兩個屬性提供了一欄的顯示名稱。例如,當欄所列在網站欄組件庫中,便會在清單中的名稱取自網站的欄位集合中每個SPField物件的Title屬性。當欄列示在特定內容類型的網站內容類型] 頁面上時,名稱是取自內容類型的欄位參照集合中每個SPFieldLink物件的DisplayName屬性。
網站欄新增至內容類型之後,您可以將SPFieldLink物件的DisplayName屬性值設定為SPField物件, Title屬性值不同的值允許使用相同的直欄定義不同的顯示名稱的內容類型。
Examples
下列範例會顯示主控台應用程式,建立Company內容類型。新的內容類型為基礎的Item內容類型,因為它會繼承參照網站欄名為"Title"。應用程式會變更此欄在從"Title"到"Company。" Company內容類型的顯示名稱若要確認內容類型] 欄中的顯示名稱現在已與網站欄的顯示名稱不同,應用程式會在列印主控台這兩個名稱。
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...
請參閱
參照
Microsoft.SharePoint namespace