Friday, June 3, 2011

Issues with RemoveFieldRef and ContentTypes

When inheriting from content types you can use RemoveFieldRef to remove unused fields. The RemoveFieldRef however is very picky when you want it to work.

Example content type “SampleInheritance” (inherits from content type: Event (0x0102))

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ContentType
ID="0x0102002748FB863AA69C449E1D30D488B1DFDD"
Name="SampleInheritance"
Description="Create a new meeting, deadline or other event."
Group="Sample"
Inherits="FALSE"
Hidden="false"
ReadOnly="false"
Sealed="false">
<FieldRefs>
<FieldRef ID="fce16b4c-fe53-4793-aaab-b4892e736d15" Name="EMail" DisplayName="E-Mail" />
<FieldRef ID="114bf263-2846-4854-839b-715c0f573cea" Name="Header1" DisplayName="Header" />
<FieldRef ID="f9589629-6f74-403e-83f6-8da3316dcca2" Name="BedankPagina" DisplayName="BedankPagina" />
<RemoveFieldRef ID="{7d95d1f4-f5fd-4a70-90cd-b35abc9b5bc8}"/>
</FieldRefs>
<XmlDocuments xmlns="http://schemas.microsoft.com/sharepoint/">
<XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
<FormTemplates xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
<Display>ListForm</Display>
<Edit>ListForm</Edit>
<New>ListForm</New>
</FormTemplates>
</XmlDocument>
</XmlDocuments>
</ContentType>
</Elements>

Follow these rules:

  1. in <RemoveFieldRef> the GUID in the ID should start with ‘{‘ and ends with ‘}’
  2. in <RemoveFieldRef> the GUID in the ID must be lowercase
  3. set "Inherits=false” or remove the attribute.

2 comments:

  1. Your post is truly informative for me and i am so grateful to you for sharing this informative post here. really great job done by you.

    ReplyDelete
  2. Now this rule in the SPCAFContrib ReSharper plugin

    http://resharper-plugins.jetbrains.com/packages/SPCAFContrib.ReSharper/

    ReplyDelete