If there are fields in a List that you need for some reason but don't want to show them to your users in certain situations, you can set them to be hidden in any of several cases. I've used this before for fields I controlled programmatically – I need them in the List Item, but never want my users to be able to see them or change them. Here's some sample code:
using (SPSite site = new SPSite(txtURL.Text))
{
SPList list = site.OpenWeb().Lists[txtListName.Text];
SPField field = list.Fields[txtFieldName.Text];
field.ShowInNewForm = false;
field.ShowInEditForm = false;
field.Update();
}
The meaning of the properties – ShowInNewForm and ShowInEditForm are pretty self explanatory. Remember to add the Update statement at the end or else the changes are lost. In addition to those shown, there are also options for
- ShowInDisplayForm
- ShowInListSettings
- ShowInVersionHistory
- ShowInViewForms