Click to Rate and Give Feedback
Community Content
In this section
Statistics Annotations (0)
Collapse All/Expand All Collapse All
This page is specific to
The 2010 product release

Other versions are also available for the following:
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
Visual Basic (Declaration)
Public Sub Reorder ( _
    internalNames As String() _
)
Visual Basic (Usage)
Dim instance As SPFieldLinkCollection
Dim internalNames As String()

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

Parameters

internalNames
Type: array<System..::.String>[]()[]
An array of strings, each containing the value of the Name property for an object in this SPFieldLinkCollection.
ExceptionCondition
ArgumentNullException

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.

Visual Basic
Dim site As SPSite = New SPSite("http://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
C#
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;
        ct.Update();
    }
}
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker