Programatically changing field order in Sharepoint 2007 list

后端 未结 3 1223
北恋
北恋 2021-01-27 03:07

I\'m adding in two new fields into an already existing Sharepoint list programmatically through a feature. The fields are being added successfully but I have been unable to adju

3条回答
  •  情歌与酒
    2021-01-27 03:43

    Here's a powershell version:

    # Moves "FieldToBeMoved" after "Description" field
    $list = $web.Lists["Documents"]
    $ct = $list.ContentTypes[0] # Or find the desired CT
    
    $newOrder = @()
    foreach ($field in $ct.Fields)
    {
        if ($field.StaticName -ne "FieldToBeMoved")
        {
            $newOrder += $field.StaticName
        }
        if ($field.StaticName -eq "Description")    
        {
            $newOrder += "FieldToBeMoved"
        }
    }
    
    $ct.FieldLinks.Reorder($newOrder)
    $ct.Update();
    

提交回复
热议问题