SPFieldLinkCollection.Reorder Method

Changes the order in which fields referenced in this collection are listed on forms.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
Public Sub Reorder ( _
    internalNames As String() _
)
'Usage
Dim instance As SPFieldLinkCollection
Dim internalNames As String()

instance.Reorder(internalNames)
public void Reorder(
    string[] internalNames
)

Parameters

  • internalNames
    Type: []

    An array of strings, each containing the value of the Name property for an object in this SPFieldLinkCollection.

Exceptions

Exception Condition
ArgumentNullException

internalNames is null .

Remarks

You can use this method to change the order in which fields are displayed on forms such as the New Item form on a list. The collection of strings that you pass as an argument to the method must contain the internal names of fields that are referenced by objects in the SPFieldLinkCollection. You can obtain a list of internal names by accessing the Name property for each object in the collection.

If you pass an incomplete list, the method places the objects named in your list in the first part of the collection, ahead of any objects whose names do not appear in your list. If your list contains a name that does not appear in the collection, the name is ignored.

Examples

The following example changes the order of fields in the default content type for the Announcements list, putting the Expires field first and making it a required field. The default order in the Announcement content type is “Title, Body, Expires.” The code sample changes the order to “Expires, Title, Body.” Note that the change desired here could also be accomplished by passing an array with only two strings, “Expires, Title”.

The application that includes this code sample imports the System and Microsoft.Sharepoint namespaces.

Dim site As SPSite = New SPSite("https://localhost")
Try
    Dim web As SPWeb = site.OpenWeb()
    Try
        Dim ct As SPContentType = web.Lists("Announcements").ContentTypes("Announcement")
        Dim flinks As SPFieldLinkCollection = ct.FieldLinks

        ' Put the Expires field first and make it required.
        flinks.Reorder(New String() {"Expires", "Title", "Body"})
        flinks("Expires").Required = True
        ct.Update()
        
    Finally
        web.Dispose()
    End Try
Finally
    site.Dispose()
End Try
using (SPSite site = new SPSite("https://localhost"))
{
    using (SPWeb web = site.OpenWeb())
    {
        SPContentType ct = web.Lists["Announcements"].ContentTypes["Announcement"];
        SPFieldLinkCollection flinks = ct.FieldLinks;

        // Put the Expires field first and make it required.
        flinks.Reorder(new[]{"Expires", "Title", "Body"});
        flinks["Expires"].Required = true;
        ct.Update();
    }
}

See Also

Reference

SPFieldLinkCollection Class

SPFieldLinkCollection Members

Microsoft.SharePoint Namespace

SPFieldLink

SPContentType

Other Resources

Fields and Field References

Introduction to Columns