SharePoint 2010: RemoveFieldRef and Inherits=“TRUE”

痞子三分冷 提交于 2019-12-21 04:29:12

问题


I have created a custom content type that inherits from the OOTB SharePoint Picture content type. The only customisations I have made is to add a simple URL field, and remove two of the fields on the base type. See below:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <!-- Parent ContentType: Picture (0x010102) -->
    <ContentType ID="0x0101020027f16ab27e6e45a6848c25c47aaa7053"
                 Name="Custom Picture"
                 Description=""
                 Group="Custom"
                 Inherits="TRUE"
                 Version="0">
        <FieldRefs>
            <RemoveFieldRef ID="{b66e9b50-a28e-469b-b1a0-af0e45486874}" Name="Keywords" />
            <RemoveFieldRef ID="{a5d2f824-bc53-422e-87fd-765939d863a5}"  Name="ImageCreateDate" />
            <FieldRef ID="{c29e077d-f466-4d8e-8bbe-72b66c5f205c}" Name="URL" DisplayName="URL" Required="FALSE" />
        </FieldRefs>
    </ContentType>
</Elements>

If I create a picture library based on my custom content type, the "URL" field that I added appears in the new/edit forms, however the two fields that I have attempted to remove are also displayed, i.e. the RemoveFieldRef's are being ignored. If I look at the content type in "Site Settings -> Content Type Gallery", these two fields are still listed there.

Setting Inherits="FALSE" on my custom content type (see MSDN definition) successfully removes just these two fields from the "Site Settings -> Content Type Gallery" page, however then none of the base fields are displayed in the new/edit forms -- only my custom "URL" field.

What can I do to ensure that all the fields from the base "Picture" content type are displayed on the new/edit forms of my picture library except the two fields that I have specifically removed?


回答1:


I believe the nature of this issue to be the understanding of how content type inheritance works.

From MSDN (http://msdn.microsoft.com/en-us/library/aa544268.aspx)

If Inherits is TRUE, the child content type inherits all fields that are in the parent, >including fields that users have added.

If Inherits is FALSE or absent and the parent content type is a built-in type, the child >content type inherits only the fields that were in the parent content type when >SharePoint Foundation was installed. The child content type does not have any fields that >users have added to the parent content type.

If Inherits is FALSE or absent and the parent content type was provisioned by a sandboxed >solution, the child does not inherit any fields from the parent.

I think the key phrase above is "If Inherits is TRUE, the child content type inherits ALL fields that are in the parent including fields that users have added."

This means that in order to accomplish what you set out to do you will have inherits set to false and you will have to include FieldRef elements for all fields you wish to use in your content type.

You make no reference / don't include code for how the content type was added to your list instance. Make sure this has been updated to support the removal or setting of inherits to false.

These sites support what is described here.

  • http://kvdlinden.blogspot.com/2011/06/issues-with-removefieldref-and.html

  • http://nelsonlamprecht.wordpress.com/2010/08/25/sharepoint-2010-removefieldref-and-inherits%E2%80%9Dtrue%E2%80%9D/



来源:https://stackoverflow.com/questions/5090383/sharepoint-2010-removefieldref-and-inherits-true

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!