sharepointmosssharepoint-2007

How do you remove/delete a column in a custom list that you added from existing site columns?


I have a custom list, and I've added a 'Page Image' field by clicking on the 'Add from existing site columns' link on the Settings page for the list. I would now like to remove the field, but clicking on the field name on the Settings page yields no 'Delete' functionality.

How do you remove fields from a custom list in SharePoint that have been added via the 'Add from existing site columns' menu item?


Solution

  • "Page Image" is a special kind of SharePoint field defined as Sealed. This means it cannot be removed from the UI once added. However it can be removed programmatically:

    SPList list = web.Lists["CustomTest"];
    SPField f = list.Fields["Page Image"];
    f.Sealed = false;
    f.Update();
    list.Fields["Page Image"].Delete();
    

    For reference, the field is defined in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\PublishingResources\PublishingColumns.xml.