Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>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:</p> <pre><code>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 } </code></pre> <p>Read the <a href="http://dotnetfollower.com/wordpress/2012/07/sharepoint-how-to-delete-a-list-fieldcolumn-programmatically/" rel="nofollow">article</a>, to learn more.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload