Thursday, May 06, 2010

FieldRef element not working with custom content type

I have been working on SharePoint 2010 for the last few weeks and have found the new development tools quite useful. So far I have been able to avoid any CAML issues like typos that plagued MOSS 2007 projects. Today I ran into something interesting however.

I was creating a custom content type with some custom site columns, but after activating all the necessary features, my content type only had site columns in it that were from the parent content type. None of the site columns defined in the FieldRefs section were included in the new content type. The logs showed no errors, and I was quite stuck. I spent a few hours experimenting and finally found the solution. Comments in the XML. Yeah, don't get me started, comments should not influence functionality but in this case they do.

So basically, this content type definition doesn't include any of the fields added in the FieldRef section:


  <ContentType ID="0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF390058d217b15a4549e79a7dfacfb6577993"
Name="Generic Page"
Description="Generic Page"
Group="My Content Types"
Sealed="FALSE"
Inherits="TRUE"
Version="0">
<FieldRefs>
<!-- Comment -->
<FieldRef ID="{4B9D42FA-8081-49AB-9F89-72FAB3C6609C}"/>
</FieldRefs>
</ContentType>

But this one does.


  <ContentType ID="0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF390058d217b15a4549e79a7dfacfb6577993"
Name="Generic Page"
Description="Generic Page"
Group="My Content Types"
Sealed="FALSE"
Inherits="TRUE"
Version="0">
<FieldRefs>
<FieldRef ID="{4B9D42FA-8081-49AB-9F89-72FAB3C6609C}"/>
</FieldRefs>
</ContentType>

The only difference is the comment. Good job and gold star to the guy who wrote the XML parser for this.




No comments: