We have three types of List Forms in SharePoint.,
New Form, Edit Form and Display Form.
For some times or in some requirements, we need to hide some of the fields in List Forms. By OOB there is no page or option for hiding fields on separate form, but we can hide the fields in all forms in List.
I am just giving snippet to hide the Fields in each separate form, separately,
using (SPSite site = new SPSite(“http://localhost”))
using (SPWeb web = site.OpenWeb())
SPList list = web.Lists.TryGetList(“Custom”);
SPField field = list.Fields.GetFieldByInternalName(“field1”);
//To hide the field from New Form
field.ShowInNewForm = false;
//To hide the field from Edit Form
field.ShowInEditForm = false;
//To hide the field from Display Form
field.ShowInDisplayForm = false;
We can also show / hide the fields based on content Types. For Content Types, we can retrieve the field from Content Type.
SPField field = list.ContentTypes["ctype1"]. Fields.GetFieldByInternalName("field1");
and the add the further lines to hide the field in SharePoint Lists.
For revert back, we can set the ShowInNewForm property as true.