Change display form fields order programmatically

20/07/2015 17:49

If we want to change fields order in new form, edit form and display form without editing aspx in Sharepoint designer, we can change it in content type through UI or programmatically.

In following example, we change order of Event content type

Add-PSSnapin microsoft.sharepoint.powershell -ea 0
$webUrl = "https://yoursitecollectionurl"
$ctName = "Event"

#note: StartDate, EndDate are fields Start Time(EventDate), End Time (EndTime) in FieldLinks references
$fieldsOrder = ("StartDate", "EndDate", "Location", "Title")

$web = Get-SPWeb $webUrl
$contentType = $web.ContentTypes[$ctName]

#see original order
$contentType.FieldLinks ' select DisplayName


#see modified order
$contentType.FieldLinks ' select DisplayName