Share via


SPContentType.FieldLinks property

取得表示集合中的內容類型的欄或欄位時,參考的SPFieldLinkCollection

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'宣告
Public ReadOnly Property FieldLinks As SPFieldLinkCollection
    Get
'用途
Dim instance As SPContentType
Dim value As SPFieldLinkCollection

value = instance.FieldLinks
public SPFieldLinkCollection FieldLinks { get; }

Property value

Type: Microsoft.SharePoint.SPFieldLinkCollection
內容型別中的欄位參考的集合。

備註

如果您想要追蹤特定內容的型別中的項目中繼資料,您可以參考該中繼資料表示的資料行。不過,您無法建立資料行中內容的型別 ;您必須建立資料行,然後在內容類型定義中參考它。如此一來時您將資料行加入內容的型別時,, 內容型別並不包含欄或欄位 ;它包含的欄或欄位時,參考

如需詳細資訊,請參閱Fields and Field References

SPContentType物件包含SPFieldLinkCollectionSPFieldCollection物件。

SPFieldCollection物件存在於該內容類型中,提供開發人員以取得資料行的屬性組合的檢視方式。每個SPField物件代表資料行或欄位,定義,加上已被覆寫,在該內容類型的欄位參照這些屬性的所有的屬性。

當您存取內容的型別中的SPField時, SharePoint Foundation將合併欄位參考的欄位定義,並會產生的SPField物件傳回給您。這可以防止開發人員不必查詢的欄位定義,並再查閱 [覆寫該內容類型的欄位參考的欄位定義中的所有屬性。

因此,沒有 1-1 之間的關聯性中的SPFieldLinkCollectionSPFieldCollection物件的項目。如您將加入至內容的型別每個SPFieldLink , SharePoint Foundation會新增對應的SPField物件,代表該資料行的 [合併] 檢視用來定義它的內容類型。

您無法直接新增或刪除項目從SPContentType物件 ; 的SPFieldCollection物件如果您嘗試執行這項操作時,會擲回錯誤。

Examples

下列範例是一個主控台應用程式,建立新的欄位,並將它加入站台的SPFieldCollection的一部份。然後應用程式會使用新的資料行的參考來建立新的SPFieldLink ,並將它加入至內容類型的**[SPFieldLinkCollection]**集合。最後,應用程式更新內容的型別,認可對資料庫所做的變更。

請注意它可以用來建立SPFieldLink物件之前,必須在站台的欄位集合中存在欄位。

Dim site As SPSite = New SPSite("https://localhost")
Dim web As SPWeb = site.OpenWeb()

' Get a reference to the site content type collection.
Dim contentTypes As SPContentTypeCollection = web.ContentTypes

' Create a Customer content type derived from the Contact content type.
Dim contentType As SPContentType = New SPContentType(contentTypes("Contact"), contentTypes, "Customer")

' Put the content type in a group.
contentType.Group = "Test"

' Add the content type to the site collection.
contentTypes.Add(contentType)

' Get a reference to the site fields (columns) collection
Dim siteFields As SPFieldCollection = web.Fields

' Create a new field (column) and add it to the site collection.
Dim fieldName As String = siteFields.Add("Last Order", SPFieldType.DateTime, False)

' Create a reference to the new field.
Dim fieldLink As SPFieldLink = New SPFieldLink(siteFields.GetField(fieldName))

' Add the field reference to the content type.
contentType.FieldLinks.Add(fieldLink)

' Commit changes to the content type.
contentType.Update()

' Clean up
web.Dispose()
site.Dispose()
SPSite site = new SPSite("https://localhost");
SPWeb web = site.OpenWeb();

// Get a reference to the site content type collection.
SPContentTypeCollection contentTypes = web.ContentTypes;

// Create a Customer content type derived from the Contact content type.
SPContentType contentType = new SPContentType(contentTypes["Contact"], contentTypes, "Customer");

// Add the content type to the site collection.
contentTypes.Add(contentType);

// Get a reference to the site fields (columns) collection.
SPFieldCollection siteFields = web.Fields;

// Create a new field (column) and add it to the site collection.
string fieldName = siteFields.Add("Last Order", SPFieldType.DateTime, false);

// Create a reference to the new field.
SPFieldLink fieldLink = new SPFieldLink(siteFields.GetField(fieldName));

// Add the field reference to the content type.
contentType.FieldLinks.Add(fieldLink);

// Commit changes to the content type.
contentType.Update();

// Clean up
web.Dispose();
site.Dispose();

請參閱

參照

SPContentType class

SPContentType members

Microsoft.SharePoint namespace

其他資源

Fields and Field References

Introduction to Columns

Introduction to Content Types

Site and List Content Types

Base Content Type Hierarchy