Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

In MOSS 2007 (the same in SharePoint 2010), I have created a custom content type "CustomPage" which inherits from "Page" in a new content type group "My Custom Columns".

Then I have added some custom site columns to CustomPage.

I have then created new content types "CustomArticle", "CustomNews", "CustomHome" which all inherit from CustomPage.

I then associate my page layouts with the relevant content types using the "Associated Content Type" field.

If I now create a new site and then a new page under that site e.g. create NewSite/Pages/NewPage.aspx with the "CustomArticle" content type, I would expect to be able to switch between my custom content types. However, if I go to the properties of the page and try to change the content type from the drop-down menu, I get the options of "Page", "Article Page", "Welcome Page" or "CustomArticle" (which is the one currently applied).

When I view the List settings for the "Pages" library underneath NewSite, I can see that my custom content types have NOT been inherited from the top level.

How do I ensure that all my custom content types are always available in libraries so that users can switch between page layouts with custom content types?

Thanks very much in advance for your help!

share|improve this question
add comment

migrated from stackoverflow.com Mar 3 '12 at 1:55

This question came from our site for professional and enthusiast programmers.

2 Answers

YOu can use a normal feature element with a ContentTypeBinding in it. It takes the list url and the content type id as attributes, the example below uses a resource for the pages url, so this will work for a site in any language, you can include as many binding as you want:

<ContentTypeBinding ContentTypeId="CTYPEID" ListUrl="$Resources:osrvcore,List_Pages_UrlName;" />

Furthermore, you bind a page layout to a specfic content type like so:

<File Url="AgoraPageContact.aspx" Type="GhostableInLibrary" >
  <Property Name="Title" Value="$Resources:YOURRESOURCEFILE,YOURTITLERESOURCEKEY;" />
  <Property Name="MasterPageDescription" Value="$Resources:YOURRESOURCEFILE,YOURDESCRIPTIONRESOURCEKEY;" />
  <Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;" />
  <Property Name="PublishingPreviewImage" Value="~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/WelcomeLinks.png, ~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/WelcomeLinks.png" />
  <Property Name="PublishingAssociatedContentType" Value=";#$Resources:YOURRESOURCEFILE,YOURCTYPENAME;;#CTYPEID;#" />
</File>

<!-- NOTICE THE DOUBLE ;; in the PublishingAssociatedContentType property! -->
share|improve this answer
add comment

You need to associate your custom Content Types with the Pages library.

Try something like this in a Feature Receiver:

private void ModifyPages(SPWeb web)
{
    SPList list = web.Lists["Pages"];
    SPContentTypeId[] ids = new SPContentTypeId[] { ContentTypeId.CustomArticle, ContentTypeId.CustomNews, ContentTypeId.CustomHome };
    foreach (SPContentTypeId id in ids)
    {
        SPContentType type = web.AvailableContentTypes[id];
        ReplaceAllContentTypesOnList(list, type);
    }
    list.Update();
}

// source: Microsoft.SharePoint.Publishing.Internal.ProvisioningHelper.ReplaceAllContentTypesOnList
private void ReplaceAllContentTypesOnList(SPList list, SPContentType contentType)
{
    List<SPContentType> types = new List<SPContentType>();
    foreach (SPContentType current in list.ContentTypes)
    {
        if (current.Id.Parent != contentType.Id)
        {
            types.Add(current);
        }
    }
    list.ContentTypes.Add(contentType);
    foreach (SPContentType type in types)
    {
        list.ContentTypes.Delete(type.Id);
    }
}
share|improve this answer
    
Thanks for your solution, so is there abosulutely no way of achieving this OOTB without writing any code? –  user653408 Mar 10 '11 at 14:09
1  
It can be done manually. Go to Library Settings > Advanced Settings, click Yes for Allow management of content types, and click OK. Then in the Content Type section click Add from existing site content types in order to add your own Content Types. –  Rich Bennema Mar 10 '11 at 14:46
    
The method @Rich states in his comment is the standard method of associating content types with a List. It's in the documentation. –  James Love Mar 10 '11 at 15:46
1  
StackOverflow is a programming help site. This question might be more appropriate at SuperUser.com or SharePointOverflow.com if you don't want an answer that involves code. –  Tom Resing Mar 11 '11 at 2:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.