none
How to hide fields in content types? RRS feed

  • Question

  • Hi

    I am creating a .wsp - package for deploying our solution in a different environment, and in that I have created Content Type and fields.

    Some of the content types are based on article page, and thus inherit publishing fields. I want to hide some of the fields that follows with publishing infrastructure feature, but that seems impossible.

    How can this field be hidden, if hidden = true doesn't work ? 

    <FieldRef ID="{3de94b06-4120-41a5-b907-88773e493458}" Name="PublishingPageImage" Required="FALSE" Hidden="TRUE" />

    I am really struck and frustrated here. I don't know what else to do.

    Please advice

    Monday, August 29, 2011 7:01 PM

Answers

  • I agree - failing all declarative options you may be forced to revert to using a feature receiver, programmatically hiding the field in the base content type, then pushing the update to all child content types. This is the default fallback option for all occassions where declarative code misbehaves, and is a guaranteed winner. The only drawback is that your content type definition is effectively split between a bunch of XML in one file and a bunch of C# in another.
    • Marked as answer by Wayne Fan Tuesday, September 6, 2011 6:54 AM
    Wednesday, August 31, 2011 9:13 PM

All replies

  • If you're happy to get rid of the field from the CT altogether you can use a RemoveFieldRef instead of a FieldRef.

    When it comes to tweaking inherited content types using the attributes of the FieldRef element I've found it pretty ineffective. I'm not sure why this is, but it might be because the field elements in the list schema are copied from the site column definition, which won't have Hidden="TRUE". Have you got a list definition you're using this content type in?

    Monday, August 29, 2011 9:44 PM
  • Microsoft says:

    The FieldRef element is a reference to a column defined elsewhere, either at the site or list level. In the field reference, you can override a subset of the column properties, such as the following:

    • Display name

    • XML promotion and demotion attributes

    • Whether the field is read-only, required, or hidden

    Changing these properties in the field reference changes them only as they apply to the specific content type that contains the field reference.

    http://msdn.microsoft.com/en-us/library/aa543225.aspx

    I've not tried hiding a field using Hidden="TRUE" in the CT definition, just RemoveFieldRef, but Microsoft seem to reckon it's possible. From experience, don't believe everything in their documentation - mostly it's just incomplete, occassionally it's totally wrong.

    Monday, August 29, 2011 9:51 PM
  • Microsoft says:

    The FieldRef element is a reference to a column defined elsewhere, either at the site or list level. In the field reference, you can override a subset of the column properties, such as the following:

    • Display name

    • XML promotion and demotion attributes

    • Whether the field is read-only, required, or hidden

    Changing these properties in the field reference changes them only as they apply to the specific content type that contains the field reference.

    http://msdn.microsoft.com/en-us/library/aa543225.aspx

    I've not tried hiding a field using Hidden="TRUE" in the CT definition, just RemoveFieldRef, but Microsoft seem to reckon it's possible. From experience, don't believe everything in their documentation - mostly it's just incomplete, occassionally it's totally wrong.


    Yup. I've tried that. Doesn't work.

    If anyone can has done it, please let me know.

    Regards

    Tuesday, August 30, 2011 4:35 PM
  • here you can see hiding contenttype field using powershell script

    http://suryapulipati.blogspot.com/2011/08/sharepoint-2010-hide-contenttype-field.html


    suryakumarp
    Tuesday, August 30, 2011 8:16 PM
  • Thanks

    But I really think it should be done in the .wsp package, because on upgrade, things will be reverted again, and not good maintenance.

    I find it to be very strange that this is seemingly impossible to achieve, but again, this is SharePoint, so..

    Wednesday, August 31, 2011 8:24 PM
  • I agree - failing all declarative options you may be forced to revert to using a feature receiver, programmatically hiding the field in the base content type, then pushing the update to all child content types. This is the default fallback option for all occassions where declarative code misbehaves, and is a guaranteed winner. The only drawback is that your content type definition is effectively split between a bunch of XML in one file and a bunch of C# in another.
    • Marked as answer by Wayne Fan Tuesday, September 6, 2011 6:54 AM
    Wednesday, August 31, 2011 9:13 PM
  • I am also facing the same issue. I tried keeping the Hidden="True", still the status of the field is showing as Optional not as Hidden. How I can handle this in XML file. Please advice asap/

    Dinesh Pulugundla, Microsoft Certified Technology Specialist.

    Thursday, September 20, 2012 10:37 AM