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.
5 Answers
"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();
f.Delete();
For reference, the field is defined in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\PublishingResources\PublishingColumns.xml
.
Attribution credit: my answer on Stack Overflow.
Besides being Sealed, a field can be read-only, hidden and etc. All these factors might prevent the field from deletion. The more suitable method to delete a list field is the following one:
public static bool RemoveField(SPField spField)
{
if (spField == null)
{
WriteErrorToLog("spField is null! Please, provide a valid one");
return false;
}
bool res = false;
try
{
// check if it's a ReadOnly field.
// if so, reset it
if (spField.ReadOnlyField)
{
spField.ReadOnlyField = false;
spField.Update();
}
// check if it's a Hidden field.
// if so, reset it
if (spField.Hidden)
{
spField.Hidden = false;
spField.Update();
}
// check if the AllowDeletion property is set to false.
// if so, reset it to true
if (spField.AllowDeletion == null || !spField.AllowDeletion.Value)
{
spField.AllowDeletion = true;
spField.Update();
}
// If the AllowDeletion property is set,
// the Sealed property seems not to be examined at all.
// So the following piece of code is commented.
/*if(spField.Sealed)
{
spField.Sealed = false;
spField.Update();
}*/
// If the AllowDeletion property is set,
// the FromBaseType property seems not to be examined at all.
// So the following piece of code is commented.
/*if(spField.FromBaseType)
{
spField.FromBaseType = false;
spField.Update();
}*/
// finally, remove the field
spField.Delete();
spField.ParentList.Update();
res = true;
}
catch (Exception ex)
{
WriteErrorToLog(ex.Message);
}
return res;
}
public static bool RemoveField(SPList spList, string displayNameOrInternalNameOrStaticName)
{
SPField spField = GetFieldByName(spList, displayNameOrInternalNameOrStaticName);
if(spField == null)
{
WriteErrorToLog(string.Format("Couldn't find field {0}!", displayNameOrInternalNameOrStaticName));
return false;
}
return RemoveField(spField);
}
public static void WriteErrorToLog(string errorMsg)
{
// write error into log
}
Read my article How to Delete a List Field/Column programmatically, to learn more.
I have seen this before when you add fields that SharePoint consider non-deletable.
You will probably have to delete it programmatically or a tool like SharePointManager
How about hiding the field using manage content types?
List Settings --> Advanced Settings -->Allow Manage content types Click on COntent Type --> click on Page Image field --> Select Hidden?
-
Unfortunately, 'Hidden' isn't sufficient for my purposes.. Commented Oct 14, 2009 at 13:26
- First go to Home option in Default Page
- Click on list name that you have created.
- Click on List setting option in setting tab pane.
- Click on Column name in Columns option
- Then you get the option to delete. Press it and it will be deleted.