When I search for documentation about creating contenttypes using code (C#) I always find examples using a SPFieldLink to link to an existing field of the site and adding this via
contentType.FieldLinks.Add()
But there is also a method to add fields directly. Is there a good reason why I should not simply add fields using
contentType.Fields.Add(SpField())
?!?
thanks in advance
It might help to look at the XML for a list.
Here is the XML for the Announcement Content Type:
Here is the XML for the Announcement List:
Lists have Fields. Content Types have FieldRefs.
I’m not sure if this is exactly right, but I always describe it as the difference between classes and interfaces or abstract classes. A Content Type is the definition for a list, but, like an interface, it does not contain any data or functionality. Since Fields contain data and functionality, Content Types (disassociated from a list) do not have Fields, they have FieldRefs. YMMV – but that always helps me keep them straight.