Skip to main content

Cloud

SharePoint Content Type Definitions and FieldRef Elements

I’ve been working on a project recently with a number of content type definitions. As you may know, there are a number of different reasons to create a content type within SharePoint: in some of those cases you may have common properties for many content types, so it’s possible to have many child content types inheriting from a single parent content type without adding additional metadata in the child types. For example, you might use this method to differentiate items for record center routing or if you desire to roll up specific information in a Content Query Web Part.

I’ll make it a little more concrete. Take the following elements.xml file as an example. The two content types defined here are inheriting from the MOSS "Page" content type that is part of the publishing feature. (If you’re not familiar with content type naming and inheritance, Ken has a nice post on it here. I’ve abbreviated the content type IDs shown below…)

   1:  <?xml version="1.0" encoding="utf-8" ?>
   2:  <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
   3:   
   4:      <!-- My Custom Page : Page -->
   5:      <ContentType ID="0x010100C568DB52D9D0A14D9B2FDCC96..." 
   6:          Name="My Custom Page"   
   7:          Group="My Content Types"
   8:          Description="Test custom page" 
   9:          Version="0">
  10:          <FieldRefs />
  11:      </ContentType>
  12:      
  13:      <!-- Another Custom Page : Page -->
  14:      <ContentType ID="0x010100C568DB52D9D0A14D9B2FDCC96..." 
  15:          Name="Another Custom Page"   
  16:          Group="My Content Types"
  17:          Description="Another custom page" 
  18:          Version="0">
  19:      </ContentType>
  20:          
  21:  </Elements>

.ExternalClassB90D55F579524A658A74A4592344C66B .csharpcode, .ExternalClassB90D55F579524A658A74A4592344C66B .csharpcode pre
{font-size:small;color:black;font-family:consolas, "Courier New", courier, monospace;background-color:#ffffff;}
.ExternalClassB90D55F579524A658A74A4592344C66B .csharpcode pre
{margin:0em;}
.ExternalClassB90D55F579524A658A74A4592344C66B .csharpcode .rem
{color:#008000;}
.ExternalClassB90D55F579524A658A74A4592344C66B .csharpcode .kwrd
{color:#0000ff;}
.ExternalClassB90D55F579524A658A74A4592344C66B .csharpcode .str
{color:#006080;}
.ExternalClassB90D55F579524A658A74A4592344C66B .csharpcode .op
{color:#0000c0;}
.ExternalClassB90D55F579524A658A74A4592344C66B .csharpcode .preproc
{color:#cc6633;}
.ExternalClassB90D55F579524A658A74A4592344C66B .csharpcode .asp
{background-color:#ffff00;}
.ExternalClassB90D55F579524A658A74A4592344C66B .csharpcode .html
{color:#800000;}
.ExternalClassB90D55F579524A658A74A4592344C66B .csharpcode .attr
{color:#ff0000;}
.ExternalClassB90D55F579524A658A74A4592344C66B .csharpcode .alt
{background-color:#f4f4f4;width:100%;margin:0em;}
.ExternalClassB90D55F579524A658A74A4592344C66B .csharpcode .lnum
{color:#606060;}

Pretty straightforward, right? These two content types inherit from the "Page" but don’t add any additional fields of their own, so they should simply inherit the fields specified by the parent.

The next step is to wrap up the file as a feature and deploy it. It deploys fine with no errors, and my two content types now appear in the site collection’s content type gallery:

2008-02-06_005030

When I click on the "My Custom Page" content type, I see exactly what I expect: all of the columns that are part of the "Page" content type are listed in the columns for this one.

mycustompage

However, when I click on the "Another Custom Page" content type, the column list looks a little, uh, emptyish.

anothercustompage

Interesting, huh? Did you notice the difference in the XML above? Take a look at line 10. The content type definition for "My Custom Page" includes an empty "FieldRefs" element, while the "Another Custom Page" content type omits it.

I’m not sure why it works this way: the documentation indicates that the FieldRefs element isn’t required — but in the event that you don’t include it, I wouldn’t expect the inheritance of parent columns to be broken.

In any case, my suggestion is when creating content type definitions, always include a FieldRefs element — even if it’s empty.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Matthew Morse

More from this Author

Follow Us