Let`s say you`re building SharePoint portal and your users have a section where they post company news. Let`s say you take advantage of SharePoint Publishing magic to take care of all of the content creation and let your users create a page representing a news and post it on the section that can be aggregated in some other section of the site: home page for that matter. Now, in order for you to be able to pull the content anywhere on the site you would want to make your news to be a content type and then use Search Query to select news content type from your site collection.
1. I start with creating a feature for my content type provisioning, here is how my Feature.xml will look like
<?xml version=”1.0″ encoding=”utf-8″?>
<Feature xmlns=”http://schemas.microsoft.com/sharepoint/”
Id=”50232DBD-17B9-4bc2-ACC5-54FF4B9A175E”
Title=”Tal : Prerequisites”
Description=”Tal : Prerequisites”
Version=”1.0.0.0″
Scope=”Site”
Hidden=”FALSE”
ActivateOnDefault=”FALSE”
AlwaysForceInstall=”TRUE”
ImageUrl=”">
<ActivationDependencies>
<!– Feature: Hab Portal Framework Publishing –>
<ActivationDependency FeatureId=”70962010-1106-2201-3301-010101010102″ />
<!– Feature: Hab Portal Framework Lists –>
<ActivationDependency FeatureId=”70962010-1106-2201-3301-010101010106″ />
<ActivationDependency FeatureId=”A392DA98-270B-4e85-9769-04C0FDE267AA” />
<!– Feature: PublishingPrerequisites –>
<ActivationDependency FeatureId=”AEBC918D-B20F-4a11-A1DB-9ED84D79C87E” />
<!– Feature: PublishingResources –>
<ActivationDependency FeatureId=”89E0306D-453B-4ec5-8D68-42067CDBF98E” />
<!– Feature: Navigation –>
</ActivationDependencies>
<ElementManifests>
<ElementManifest Location=”ContentTypes.xml” />
<ElementManifest Location=”Fields.xml” />
<ElementManifest Location=”PageLayouts.xml” />
<ElementManifest Location=”DelegateControls.xml” />
<ElementFile Location=”PageLayouts\TalIncident.aspx” />
<ElementFile Location=”PageLayouts\TalLanding.aspx” />
<ElementFile Location=”PageLayouts\TalNews.aspx” />
<ElementFile Location=”PageLayouts\TalEvents.aspx” />
</ElementManifests>
</Feature>
<?xml version=”1.0″ encoding=”utf-8″?>
<Feature xmlns=”http://schemas.microsoft.com/sharepoint/”
Id=”50232DBD-17B9-4bc2-ACC5-54FF4B9A175E”
Title=”My: Content Type Provisioning”
Description=”My: Content Type Provisioning”
Version=”1.0.0.0″
Scope=”Site”
Hidden=”FALSE”
ActivateOnDefault=”FALSE”
AlwaysForceInstall=”TRUE”
ImageUrl=”">
<ElementManifests>
<ElementManifest Location=”ContentTypes.xml” />
<ElementManifest Location=”Fields.xml” />
<ElementManifest Location=”PageLayouts.xml” />
<ElementManifest Location=”ContentTypeBinding.xml” />
<ElementFile Location=”PageLayouts\MyPage.aspx” />
</ElementManifests>
</Feature>
Now to ContentTypes.xml which will define my new content type based on the existing Article content type. Navigate here: http://[your site]/_layouts/mngctype.aspx and take a note of Article Page under Page Layout Content Types . If you click on it, you will be taken to a page where you will see all of your Article columns; also, in your URL you will see the value of ctype takea copy of that, since we`ll need it to extending the existing content type.
Here is my ContentTypes.xml
<?xml version=”1.0″ encoding=”utf-8″ ?>
<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”>
<!– Inherits from Article Page –>
<ContentType ID=”0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D01″
Name=”MyArticlePage”
Description=”My Article Page”
Group=”My Pages”
Version=”0″
Sealed=”FALSE”
Hidden=”FALSE”
ReadOnly=”FALSE”>
<FieldRefs>
<FieldRef ID=”{77CCD82A-A86C-4347-881F-FEDBDA7951FD}” Name=”Category” />
</FieldRefs>
</ContentType>
</Elements>
Above, in bold, we see the ID of the out of the box content type ID plus `01` denoting new content type based on the parent Article. You will also notice we have a field called Category. This is a custom field that Article doesnqt have, but we want to have. Moving on to defining it in Fields.xml:
<?xml version=”1.0″ encoding=”utf-8″ ?>
<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”>
<Field ID=”{77CCD82A-A86C-4347-881F-FEDBDA7951FD}”
Name=”NewsCategory”
DisplayName=”Category”
StaticName=”NewsCategory”
Type=”Choice”
Group=”My Fields”
Required=”TRUE”
Format=”Dropdown”
FillInChoice=”FALSE” >
<CHOICES>
<CHOICE>My Department News</CHOICE>
<CHOICE>Their Department News</CHOICE>
</CHOICES>
</Field>
</Elements>
This is just a simple drop down list of choices. I make sure my content type references the same field by using a GUID. Make sure when defining your field have it`s GUID in curly braces otherwise SharePoint won`t provision it.
Next on, MyPage.aspx – just an ASPX page defining all of the edit boxes etc used in my news Article. We need to provision our Layout page to masterpage gallery and associate our content type with it by using the following PageLayouts.xml:
<?xml version=”1.0″ encoding=”utf-8″ ?>
<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”>
<!– page layouts –>
<Module Name=”PageLayouts” Url=”_catalogs/masterpage” Path=”PageLayouts” RootWebOnly=”TRUE”>
<File Url=”MyNews.aspx” Type=”GhostableInLibrary”>
<Property Name=”Title” Value=”My News Page Layout” />
<Property Name=”MasterPageDescription” Value=”My News Page Layout” />
<Property Name=”ContentType” Value=”MyArticlePage” />
<Property Name=”PublishingAssociatedContentType” Value=”;#MyArticlePage;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D01;#” />
</File>
</Module>
</Elements>
There you have it. Our page is provisioned and associated with a content type. Lastly, we need to allow this kind of a Content Type to be provisioned into the Pages library, where all of the publishing pages – including our news article – are stored. We do it in ContentTypeBinding.xml
<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”>
<!– Incident Page –>
<ContentTypeBinding
ContentTypeId=”0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D01″ ListUrl=”$Resources:cmscore,List_Pages_UrlName;” />
</Elements>