SPFieldLink constructor
初始化SPFieldLink類別與指定之欄位的新執行個體。
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public Sub New ( _
field As SPField _
)
'用途
Dim field As SPField
Dim instance As New SPFieldLink(field)
public SPFieldLink(
SPField field
)
參數
field
Type: Microsoft.SharePoint.SPField若要參考資料行。請注意這個物件必須代表現有的網站或清單欄。也就是說,它必須包含由SPWeb.Fields屬性或SPList.Fields屬性所傳回SPFieldCollection物件中。
備註
建立SPFieldLink物件之後,及其屬性的部分的初始化方式做為引數傳遞給建構函式SPField物件對應屬性的值。下表列出的內容及值。
屬性 |
從值 |
---|---|
Examples
下列範例顯示會SPField物件新增到網站的SPFieldCollection,然後使用物件來建立SPFieldLink物件,並將該物件新增至內容類型SPFieldLinkCollection主控台應用程式的一部分。
請注意您可以使用新的欄位建立SPFieldLink物件之前,欄位必須是欄位集合的網站或清單層級的成員。
Dim site As SPSite = New SPSite("https://localhost")
Dim web As SPWeb = site.OpenWeb()
' Get 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")
' Add the content type to the site collection.
contentTypes.Add(contentType)
' Get 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 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 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();
請參閱
參照
Microsoft.SharePoint namespace