How to hide content type choice control in edit forms

If you want the edit form of a particular list to don’t show some field, you can change the ContentType definition by setting ShowInEditForm=”FALSE” in corresponding FieldRef element.

If you want to do the same with Content Type field, the above hint simply don’t work.

To make it working you have to modify the rendering template of the edit form. To do this you have to create a new rendering template:

  1. copy the standard ListForm template from DefaultTemplates.ascx (ControlTemplate folder)
  2. create a new ascx file in the same folder and paste ListForm template
  3. change the template id to MyCustomForm
  4. remove the Sharepoint ContentTypeChoice control from the custom template

Then you have to associate the edit form to the custom template created above, to do this you can modify the content type definition inserting XmlDocuments tag under ContentType tag like in the following example:

 <XmlDocuments>
  <XmlDocument 
  NamespaceURI="https://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
    <FormTemplates  
    xmlns="https://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
      <Display>ListForm</Display>
      <Edit>MyCustomForm</Edit>
      <New>ListForm</New>
    </FormTemplates>
  </XmlDocument>
</XmlDocuments>

If you don’t have content type you can change the list definition schema by using the following code:

 <Forms>
  <Form Type="DisplayForm" 
        Url="DispForm.aspx" 
        SetupPath="pages\form.aspx" 
        WebPartZoneID="Main" />
  <Form Type="EditForm" 
        Url="EditForm.aspx" 
        SetupPath="pages\form.aspx" 
        Template="MyCustomForm" 
        WebPartZoneID="Main" />
  <Form Type="NewForm" 
        Url="NewForm.aspx" 
        SetupPath="pages\form.aspx" 
        WebPartZoneID="Main" />
</Forms>

HTH
Dario

Technorati Tag: Sharepoint,MOSS