none
Provisioning Pages with custom contenttypes using SiteDefinitions RRS feed

  • Question

  • I am trying to provision a custom welcomepage using a module in a site definition, using the following syntax:

    <Module Name="Home" Url="$Resources:cmscore,List_Pages_UrlName;">
          <File Url="default.aspx" Type="GhostableInLibrary" >
            <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/CustomWelcomePage.aspx, Custom Welcome Page" />
            <Property Name="Title" Value="Hello world" />
            <Property Name="ContentType" Value="MyCustomContentType" />
          </File>
    </Module>

    My page gets created using the PublishingPageLayout specified, however the underlying contenttype is set to Page.

    MyCustomContentType inherits from page, and exists in the sitecollection when creating the site.

    If i create a new page using my Page Layout "Custom Welcome Page" the underlying contenttype is correctly set to "MyCustomContentType"

    Any help on this matter would be greatly appreciated

    Friday, March 16, 2007 12:55 PM

Answers

  • Hi Morten

     

    You can do this declaratively by creating a content type binding feature like this:

     

    feature.xml:

     

    <Feature xmlns="http://schemas.microsoft.com/sharepoint/" Id="<Your feature guid>"
      Title="<Your feature title>" Scope="Web" Hidden="FALSE" Version="1.0.0.0">
      <ElementManifests>
        <ElementManifest Location="ContentTypeBinding.xml" />
      </ElementManifests>
    </Feature>

    ContentTypeBinding.xml:

     

    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <ContentTypeBinding ContentTypeId="0x.........." ListUrl="Pages" />
      <ContentTypeBinding ContentTypeId="0x.........." ListUrl="Pages" />
      </Elements>

    • Proposed as answer by Ted A Thursday, November 20, 2008 6:05 PM
    • Marked as answer by Steven AndrewsEditor Thursday, July 5, 2012 4:37 PM
    Thursday, May 24, 2007 10:38 AM
  • Hi Daniel

     

    You probavly figured this out by now, but here it comes

     

    My Feature XML looks like:

     

    <Feature Id="b1658282-7af8-44a9-95c4-373222d1d07f"

    Title="Content Type Provisioner"

    Description="This feature adds the specified contenttype to a publishing site"

    Version="1.0.0.0"

    Scope="Web"

    Hidden="True"

    DefaultResourceFile="core"

    Creator="ProActive A/S"

    ActivateOnDefault="True"

    AlwaysForceInstall="True"

    ImageUrl="PAFeature.gif"

    ReceiverAssembly="ProActive.Deployment, Version=1.0.0.0, Culture=neutral, PublicKeyToken=58c74dd9a182ee8e"

    ReceiverClass="ProActive.Deployment.ContentTypeProvisionerFeatureHandler"

    xmlns="http://schemas.microsoft.com/sharepoint/">

    <ElementManifests>

    </ElementManifests>

    </Feature>

     

     

    The content of my Feature Event Reciever looks like:

     

    public class ContentTypeProvisionerFeatureHandler : SPFeatureReceiver

    {

    public override void FeatureActivated(SPFeatureReceiverProperties properties)

    {

    SPWeb web = (SPWeb)properties.Feature.Parent;

    if(PublishingWeb.IsPublishingWeb(web))

    {

    PublishingWeb pweb = PublishingWeb.GetPublishingWeb(web);

    SPList pagesList = pweb.PagesList;

    if(properties.Feature.Properties["ContentTypesToAdd"] != null)

    {

    string contentTypesToAdd = properties.Feature.Properties["ContentTypesToAdd"].Value;

    foreach(string contentTypeName in contentTypesToAdd.Split(';'))

    {

    SPContentType contentType = web.Site.RootWeb.ContentTypes[contentTypeName];

    pagesList.ContentTypes.Add(contentType);

    }

    }

    web.Update();

    }

    }

    ......

    }

     

     

    In my onet.xml i have added the feature registration to the webfeatures section

     

    <Feature ID="b1658282-7af8-44a9-95c4-373222d1d07f">

    <!-- Content Type Provisioning -->

    <Properties xmlns="http://schemas.microsoft.com/sharepoint/">

    <Property Key="ContentTypesToAdd" Value="ProActive Page;Forsvaret Page;Artikel"/>

    </Properties>

    </Feature>

     

    tadaah!
    Tuesday, April 10, 2007 8:43 PM
  • Hi, Flemming!

     

    In my solution I've used feature stapling to associate the content type binding feature with the site definition. I've had some problems getting my features activated just referencing them in the site definition so I seem to use feature stapling for most of my features. (Until someone leads me out of the dark...) Maybe that's why it works for me? These are my files for the stapler feature:

     

    Feature.xml:

    <?xml version="1.0" encoding="utf-8" ?>
    <Feature Id="<my feature guid>" Title="My Feature Stapler" Version="12.0.0.0" Scope="Farm" xmlns="http://schemas.microsoft.com/sharepoint/" DefaultResourceFile="_Res">
      <ElementManifests>
        <ElementManifest Location="MyFeatureStapler.xml" />
      </ElementManifests>
    </Feature>

     

    MyFeatureStapler.xml:

    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <FeatureSiteTemplateAssociation Id="<my feature guid>" TemplateName="MYSITEDEF#0" />
    </Elements>

     

    Frank

    Thursday, May 31, 2007 2:06 PM

All replies

  • You probably figured out this one by now, but anyway... You must use:

    <Property Name="PublishingAssociatedContentType" Value=";#MyCustomContentType;#UniqueID;#" />

    You will find the unique id by looking at the url for a content type. It is extensive and starts with 0x01.....

    Frank

    Thursday, March 22, 2007 12:41 PM
  • I have been able to use this setting, works fine but according to what I do you should change the value to twice the name of the page:

    <Module ....>
     <File Url="default.aspx" Type="GhostableInLibrary" >

     <Property Name="Title" Value="Hello World" />

     <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/MyPageLayout.aspx, ~SiteCollection/_catalogs/masterpage/MyPageLayout.aspx" />

     <Property Name="ContentType" Value="MyContentType" />

    ...
    </Module>

    So, the only thing you are missing is that you typed in the name (and not URL) of the page layout as the second value of your property.

    Hope this helps!

     

    Friday, March 23, 2007 8:47 AM
  • Thank you Frank and Katrien for your responses

    However i have still not been able to provision my default page using your input.

    I have tried almost every possible combination of ContentType, PublishingAssociatedContentType and PublishingPageLayout

    <Module Name="CustomHome" Url="$Resources:cmscore,List_Pages_UrlName;">
          <File Url="default.aspx" Type="GhostableInLibrary" >
            <Property Name="Title" Value="Yahoo" />
            <Property Name="MasterPageDescription" Value="$Resources:spscore,DefaultLayoutDescription;" />
            <Property Name="ContentType" Value="Forsvaret Page" />
            <Property Name="PublishingAssociatedContentType" Value=";#Forsvaret Page;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39004A85D16F25DBAB4B902092121646076801;#" />
            <Property Name="PublishingPreviewImage" Value="~SiteCollection/_catalogs/masterpage/Preview Images/cilayout_picker.gif, ~SiteCollection/_catalogs/masterpage/Preview Images/cilayout_picker.gif" />
            <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/fvr_WelcomePage.aspx, ~SiteCollection/_catalogs/masterpage/fvr_WelcomePage.aspx" />
          </File>
    </Module>

    Have you successfully provisioned pages, based on a custom contenttype, using a sitedefinition?

    Friday, March 23, 2007 1:09 PM
  • Hi Morten,

    I have already successfully implemented a custom site definition using custom content types, custom master pages and custom page layouts. It works really well.

    Have you created your custom page layout and content types using features? If yes you also need to heirs IDs tthem in the site or web features section of the onet XML file. If you are not using features then maybe this is why you have a problem?

    I'm actually only using the properties ContenType and PublishingPageLayout, not the PublishingAssociatedContentType.

    Are you creating your site definition onet.xml file from scratch? I used the BLANKINTERNET one as a starting point. You might not need all the configurations in that onet.xml file but it gives a good overview of properties and settings that can be used.

     

    Saturday, March 24, 2007 6:54 PM
  • Hi Katrien

    I think you have pinpointed the root of my problem!

    I have deployed my contenttypes and pagelayouts using features. I have used the BLANKINTERNET as template for my sitedefinition.

    What do you mean by "If yes you also need to heirs IDs tthem in the site or web features section of the onet XML file.?

    Should I include a reference to the feature in which i defined my content types?

     

    Monday, March 26, 2007 9:43 AM
  • Hi Katrien

     

    I digged further into my problem and have comed to the following conclusion:

     

    The reason why my pages created with the SiteDefinition have their contenttypes set to Page, is beacuse the Pages library of the newly created site do not have my custom content types associated.

     

    I have manged to overcome this by creating a new Feature with scope set to Web that adds my custom content types to the Pages Library before creating the pages, that seems to work.

     

    Do you know if there is a declarative way to do this, it seems kindof developer unfriendly otherwise?

    Tuesday, March 27, 2007 7:46 AM
  • hi,

    I have exactly the same issue. Can you tell me, how do you write the web scoped feature? What must I do? I'm new on MOSS developing!!

    Or Katrien: Can you post a sample how I can add the content type id to the onet.xml?

     

    thanks

    Sorry 4 my very bad english

    regards

    Tuesday, April 3, 2007 9:05 PM
  • Hi Daniel

     

    You probavly figured this out by now, but here it comes

     

    My Feature XML looks like:

     

    <Feature Id="b1658282-7af8-44a9-95c4-373222d1d07f"

    Title="Content Type Provisioner"

    Description="This feature adds the specified contenttype to a publishing site"

    Version="1.0.0.0"

    Scope="Web"

    Hidden="True"

    DefaultResourceFile="core"

    Creator="ProActive A/S"

    ActivateOnDefault="True"

    AlwaysForceInstall="True"

    ImageUrl="PAFeature.gif"

    ReceiverAssembly="ProActive.Deployment, Version=1.0.0.0, Culture=neutral, PublicKeyToken=58c74dd9a182ee8e"

    ReceiverClass="ProActive.Deployment.ContentTypeProvisionerFeatureHandler"

    xmlns="http://schemas.microsoft.com/sharepoint/">

    <ElementManifests>

    </ElementManifests>

    </Feature>

     

     

    The content of my Feature Event Reciever looks like:

     

    public class ContentTypeProvisionerFeatureHandler : SPFeatureReceiver

    {

    public override void FeatureActivated(SPFeatureReceiverProperties properties)

    {

    SPWeb web = (SPWeb)properties.Feature.Parent;

    if(PublishingWeb.IsPublishingWeb(web))

    {

    PublishingWeb pweb = PublishingWeb.GetPublishingWeb(web);

    SPList pagesList = pweb.PagesList;

    if(properties.Feature.Properties["ContentTypesToAdd"] != null)

    {

    string contentTypesToAdd = properties.Feature.Properties["ContentTypesToAdd"].Value;

    foreach(string contentTypeName in contentTypesToAdd.Split(';'))

    {

    SPContentType contentType = web.Site.RootWeb.ContentTypes[contentTypeName];

    pagesList.ContentTypes.Add(contentType);

    }

    }

    web.Update();

    }

    }

    ......

    }

     

     

    In my onet.xml i have added the feature registration to the webfeatures section

     

    <Feature ID="b1658282-7af8-44a9-95c4-373222d1d07f">

    <!-- Content Type Provisioning -->

    <Properties xmlns="http://schemas.microsoft.com/sharepoint/">

    <Property Key="ContentTypesToAdd" Value="ProActive Page;Forsvaret Page;Artikel"/>

    </Properties>

    </Feature>

     

    tadaah!
    Tuesday, April 10, 2007 8:43 PM
  • Morten, thanks for that extra post, this is exactly what I ended up doing as well.

    I made a reference to such a feature in the onet.xml <WebFeatures> section  and now every time a new site/sub-site is created the content types are automatically added to the Page's library of the new site.

     

    Daniel, you must only specify the Content type name and the publishing page layout in the onet.xml file,  not the ID. Then do as in Morten's post by using a feature to add the content type to the Page's library once the site is generated.

     

     

    Thursday, April 12, 2007 12:38 PM
  • many thanks Morten provide this programming style resolution, i came into this problem and spend a lot of time on trying every combination to provide the correct contenttype

     

    i believe morten found the very reason:

    "The reason why my pages created with the SiteDefinition have their contenttypes set to Page, is beacuse the Pages library of the newly created site do not have my custom content types associated."

     

    the pages list is came from publishing feature, where you can find the pages folder, and schema.xml in pages folder, AFAIK the pages list is a list template, publishing feature contains a PagesListTemplate.xml file, and the associated contenttype is defined in schema.xml, to my surprise, it defined two contenttypes, Document and Folder:

        <ContentTypes>
          <ContentTypeRef ID="0x0101">
            <Folder TargetName="Forms/Document" />
          </ContentTypeRef>
          <ContentTypeRef ID="0x0120" />
        </ContentTypes>

    not my expected contenttypes like Page, ArticlePage and WelcomePage,  so originally pages list is not associated with page contenttype also,

     

    my question is: blankinternetsite provisions default.aspx to pages list by solution as Morten provided? or can you provision a publishing page to pages list with correct contenttype?

    anyone know how to associate the contenttypes with pages list in new fearue? not within publishing feature

    Thursday, May 24, 2007 8:02 AM
  • Hi Morten

     

    You can do this declaratively by creating a content type binding feature like this:

     

    feature.xml:

     

    <Feature xmlns="http://schemas.microsoft.com/sharepoint/" Id="<Your feature guid>"
      Title="<Your feature title>" Scope="Web" Hidden="FALSE" Version="1.0.0.0">
      <ElementManifests>
        <ElementManifest Location="ContentTypeBinding.xml" />
      </ElementManifests>
    </Feature>

    ContentTypeBinding.xml:

     

    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <ContentTypeBinding ContentTypeId="0x.........." ListUrl="Pages" />
      <ContentTypeBinding ContentTypeId="0x.........." ListUrl="Pages" />
      </Elements>

    • Proposed as answer by Ted A Thursday, November 20, 2008 6:05 PM
    • Marked as answer by Steven AndrewsEditor Thursday, July 5, 2012 4:37 PM
    Thursday, May 24, 2007 10:38 AM
  • thanks, Frank, you are the man  Smile   you really shoot it   Smile

     

     

    Friday, May 25, 2007 1:49 AM
  • Hi Frank

     

    Thank you a million times, i will try to use ContentTypeBindings on my new deployment project.

     

    I even opened a partner premier support case at Microsoft, and they were not able to point me in the right direction - i guess the one hande does not know what the other does!

     

    you rule!

     

    Morten

    Wednesday, May 30, 2007 12:06 PM
  • Hi,

     

    I have been trying to use the ContentTypeBinding to the way that Frank just described it using a feature.

     

    I have installed the feature manually through stsadm and then added a feature element entry in the configuration/webfeatures section in the onet.xml file for the site definition. The result of this is an "unknown error" message when I try to create a site based on the template. The eventlog just display an error "Value cannot be null" in the SPFeatureManager.EnsureFeaturesActivated.

     

    If I create the site without referencing the feature in the onet.xml file, it completes with succes and if I then manually activate the feature using the UI of MOSS, then the feature gets activated and the contenttype gets associated with the Pages list.

     

    I have tried a lot of combinations now and I seriously consider using a feature eventhandler, since it can be debugged and as Morten showed, can do the job.  It is frustrating however, not to be able to debug and resolve what should be just a simple task.

     

    I have added Activationdependencies to ensure that the feature defining the content type is activated beforehand. I have tried ading it to a toplevel site and sub level site - none of them works when using the contenttypebinding in the onel.xml file.

     

    Any suggestions on how to solve this issue the declarative way is highly appreciated!

    Thursday, May 31, 2007 10:50 AM
  • Hi, Flemming!

     

    In my solution I've used feature stapling to associate the content type binding feature with the site definition. I've had some problems getting my features activated just referencing them in the site definition so I seem to use feature stapling for most of my features. (Until someone leads me out of the dark...) Maybe that's why it works for me? These are my files for the stapler feature:

     

    Feature.xml:

    <?xml version="1.0" encoding="utf-8" ?>
    <Feature Id="<my feature guid>" Title="My Feature Stapler" Version="12.0.0.0" Scope="Farm" xmlns="http://schemas.microsoft.com/sharepoint/" DefaultResourceFile="_Res">
      <ElementManifests>
        <ElementManifest Location="MyFeatureStapler.xml" />
      </ElementManifests>
    </Feature>

     

    MyFeatureStapler.xml:

    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <FeatureSiteTemplateAssociation Id="<my feature guid>" TemplateName="MYSITEDEF#0" />
    </Elements>

     

    Frank

    Thursday, May 31, 2007 2:06 PM
  • Hi,

     

    Hmm, I haven't heard about Feature stapling before, but it sounds like it could help me - I will definitely give it a try.. will post if it works..

     

    I see it is scoped for the farm, so no matter where the sitetemplate is used in the farm you would ensure feature activation on the site template...

     

    Thanks.

     

    Flemming

     

     

    Thursday, May 31, 2007 2:26 PM
  • Hi,

     

    sorry for the late answer, but I'm very very strange work on sitedefinitions Smile

     

    your post was 2 days too late, I have found my solution in a feature with contenttypebinding. Exactly the same how Frank Jusnes wrote and a wonder.... it works Smile

     

    Greetz

     

    Daniel

     

     

    Thursday, May 31, 2007 8:37 PM
  • Hi Frank,

     

    Just want to tell that the feature stapling did the job. No difference in the feature definition that establishes the association between the content type and list - just another way to activate the feature - weird behaviour! Leaves you in doubt about how much you can trust the concept of referencing features within the configurations.

     

    Anyway - thank you once again for posting the solution.

     

    Flemming

    Friday, June 1, 2007 10:02 AM