Freigeben über


SPFieldLink-Konstruktor

Initialisiert eine neue Instanz der SPFieldLink -Klasse mit dem angegebenen Feld.

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

Syntax

'Declaration
Public Sub New ( _
    field As SPField _
)
'Usage
Dim field As SPField

Dim instance As New SPFieldLink(field)
public SPFieldLink(
    SPField field
)

Parameter

Hinweise

Wenn ein SPFieldLink -Objekt erstellt wird, werden einige der Eigenschaften mit den Werten der entsprechenden Eigenschaften des Objekts SPField initialisiert, die als Argument an den Konstruktor übergeben wird. In der folgenden Tabelle sind die Eigenschaften und deren Werte aufgeführt.

Eigenschaft

Wert aus der

Hidden

SPField.Hidden

Id

SPField.Id

Name

SPField.InternalName

Required

SPField.Required

Beispiele

Das folgende Beispiel zeigt einen Teil einer Konsolenanwendung, die die Website SPFieldCollection, ein SPField -Objekt hinzugefügt und klicken Sie dann das Objekt zum Erstellen eines SPFieldLink -Objekts verwendet, und einen Inhaltstyp SPFieldLinkCollectiondieses Objekt hinzugefügt.

Beachten Sie, dass bevor Sie ein neues Feld zum Erstellen eines SPFieldLink -Objekts verwenden können, das Feld ein Mitglied einer Feldauflistung auf Ebene der Website oder Liste sein muss.

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();

Siehe auch

Referenz

SPFieldLink Klasse

SPFieldLink-Member

Microsoft.SharePoint-Namespace

Weitere Ressourcen

Fields and Field References

FieldRef Element (ContentType)

Introduction to Columns

Introduction to Content Types