List Schema.xml Weirdness With Content Types


So I was helping another consultant fix some odd behavior he was experiencing when editing the XSL of a List View in SharePoint 2010. After we started digging we noticed we couldn’t even change the names of columns or delete them using the UI. This list was being generated from a solution that had a list schema, content type schema and list instance. The schema was built using the Visual Studio 2010 wizard for list from existing content type.

So when we started digging we noticed that the list schema that was being generated had a content type definition with the same GUID as the content type schema. Instead of using the ContentTypeRef. So once we removed the ContentType and went to ContentTypeRef everything worked great. One of those hard to figure out gotcha’s, and one that I wouldn’t expect SharePoint to allow.

Example of the issue:

Fix listed first referencing the ID of the content type to have in the list followed by an example of what visual studio was doing.

  1. <ContentTypes>
  2. <ContentTypeRef ID=“0x0101” />
  3. </ContentTypes>
  4. <ContentType ID=“0x0101”
  5. Name=“$Resources:Document”
  6. Group=“$Resources:Document_Content_Types”
  7. Description=“$Resources:DocumentCTDesc”
  8. V2ListTemplateName=“doclib”
  9. Version=“0”>
  10. <FieldRefs>
  11. <FieldRef ID=“{5f47e085-2150-41dc-b661-442f3027f552}” Name=“SelectFilename” />
  12. <FieldRef ID=“{8553196d-ec8d-4564-9861-3dbe931050c8}” Name=“FileLeafRef” Required=“TRUE”/>
  13. <FieldRef ID=“{8c06beca-0777-48f7-91c7-6da68bc07b69}” Name=“Created” Hidden=“TRUE” />
  14. <FieldRef ID=“{fa564e0f-0c70-4ab9-b863-0177e6ddd247}” Name=“Title” Required=“FALSE” ShowInNewForm=“FALSE” ShowInEditForm=“TRUE”/>
  15. <FieldRef ID=“{28cf69c5-fa48-462a-b5cd-27b6f9d2bd5f}” Name=“Modified” Hidden=“TRUE” />
  16. <FieldRef ID=“{822c78e3-1ea9-4943-b449-57863ad33ca9}” Name=“Modified_x0020_By” Hidden=“FALSE”/>
  17. <FieldRef ID=“{4dd7e525-8d6b-4cb4-9d3e-44ee25f973eb}” Name=“Created_x0020_By” Hidden=“FALSE” />
  18. </FieldRefs>
  19. <XmlDocuments>
  20. <XmlDocument NamespaceURI=“http://schemas.microsoft.com/sharepoint/v3/contenttype/forms”>
  21. <FormTemplates xmlns=“http://schemas.microsoft.com/sharepoint/v3/contenttype/forms”>
  22. <Display>DocumentLibraryForm</Display>
  23. <Edit>DocumentLibraryForm</Edit>
  24. <New>DocumentLibraryForm</New>
  25. </FormTemplates>
  26. </XmlDocument>
  27. </XmlDocuments>
  28. </ContentType>

Further resources:
MSDN – Understanding Schema.xml
Andrew Connell – A Quicker Way to Create Custom SharePoint List Templates
 

  1. #1 by aaron on February 3, 2012 - 9:41 am

    I jsut trying to figure out how to edit an existing list. I need to add a custom contentn type to the attendees list (part of the meeting workspace) I cant figure out how to edit the xml, at all.

  2. #2 by aaron on February 3, 2012 - 9:41 am

    I jsut trying to figure out how to edit an existing list. I need to add a custom contentn type to the attendees list (part of the meeting workspace) I cant figure out how to edit the xml, at all.

  3. #3 by Maarten on February 6, 2012 - 10:45 am

    First, you’ll need to use both ContentTypeBinding (add content to existing list instances) and ContentTypeRef (add content type to new list instances) for this.

    Some good references for getting something working out of them 🙂

    http://msdn.microsoft.com/en-us/library/aa543822.aspx
    http://stefan-stanev-sharepoint-blog.blogspot.com/2010/03/contenttypebinding-vs-contenttyperef.html

(will not be published)


%d bloggers like this: