Feature and Content Type to create a web part page library
August 30th, 2008 — ¥ong¥sHere are one good scenario and solution on Feature and Content Type to create a web part page library from my colleague.
The problem
The goal of this exercise is to have a document library act as a store for web part pages and for the “New document” button to create a web part page with my custom content type’s attributes.
Here’s the content type:
<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”>
<ContentType
ID=”0×010109010097431DDCD27A4eedA052535AA74AD98A”
Name=”Content Zone Page Template”
Group=”CMS Content Types”
Description=”Content type for Content Zone Page Templates”
>
<FieldRefs>
<FieldRef ID=”{29B7EF45-7669-4572-A42A-823559212C15}”
Name=”cmsDisplayName”
Required =”TRUE”
/>
</FieldRefs>
</ContentType>
<ContentTypeBinding
ContentTypeId=”0×010109010097431DDCD27A4eedA052535AA74AD98A”
ListUrl=”ContentZoneTemplates”
/>
</Elements>
And the List Instance:
<ListInstance
FeatureId=”00BFEA71-E717-4E80-AA17-D0C71B360101″
Id=”3001″
TemplateType=”101″
Title=”Content Zone Templates”
Url=”ContentZoneTemplates”
Description =”CMS Base: Content Zone Templates”
DocumentTemplate=”106″
/>
Now, I’ve tried the list instance without a document template, but that makes the default “new” item a template.doc. Using the document template as “106″ brings up a file called “_webpartpage.htm” but asks if you want to open it rather than just opening it.
The default behavior if you create a document library and set it’s content type to web part page (all through the UI) is that it first opens that _webpartpage.htm file which then redirects to the spcf.aspx page, but with knowledge of which document library you came from.
The Solution
In the content type definition, add a document template element pointing to the new web part page form. So, it looks like this now (the addition for the solution is highlighted in yellow):
<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”>
<ContentType
ID=”0×010109010097431DDCD27A4eedA052535AA74AD98A”
Name=”Content Zone Page Template”
Group=” CMS Content Types”
Description=”Content type for Content Zone Page Templates”
>
<FieldRefs>
<FieldRef ID=”{29B7EF45-7669-4572-A42A-823559212C15}”
Name=”cmsDisplayName”
Required =”TRUE”
/>
</FieldRefs>
<DocumentTemplate TargetName=”/_layouts/spcf.aspx” />
</ContentType>
<ContentTypeBinding
ContentTypeId=”0×010109010097431DDCD27A4eedA052535AA74AD98A”
ListUrl=”ContentZoneTemplates”
/>
</Elements>
* Thanks to Jesicca who share out this KB.