Hide Fields in List Forms

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; 
                    field.Update();
                }
            }

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.

Shantha Kumar
Shantha Kumar
Articles: 278

24,849 Comments

  1. If you want to hide some field from the List or Library, you can use the property SPField.ShowInNewForm , SPField.ShowInEditForm, SPField.ShowInDisplayForm to hide the fields from the forms.

    Step 1: Get the List or Content Type
    Step 2: Get the Field from List or Content Type
    Step 3: Set the value for the property
    (SPField.ShowInNewForm , SPField.ShowInEditForm, SPField.ShowInDisplayForm) to show or hide the Field in respective forms.
    Step 4:update the field.

Comments are closed.