Export (0) Print
Expand All

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)

public void Reorder(
	string[] internalNames


Type: []

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


internalNames is null .

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.

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.

using (SPSite site = new SPSite("http://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;
© 2014 Microsoft