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

I'm provisioning a bunch of Publishing pages using a feature, using the template redirection technique.

<Module Name="Page-Not-Found" Url="$Resources:cmscore,List_Pages_UrlName;">
    <File Url="Page-Not-Found.aspx" Path="Root\template.aspx" Type="GhostableInLibrary">
      <Property Name="Title" Value="Page Not Found"/>
      <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/MyPageLayout.aspx, My Page Layout Name" />
      <Property Name="ContentType" Value="My Content Type Name" />
    </File>
</Module>

The pages are provisioned correctly:

  • The Title property is set correctly
  • The page is created using the appropriate page layout and is bound to the correct content type
  • It's not shown here, but I can also use AllUsersWebPart to provision web parts onto the page

The problem I'm having is that I'm unable to populate the Html fields on the page with content; for example, by adding a property like:

<Property Name="PageContent1" Value="&lt;h1&gt;Page Not Found&lt;/h1&gt;&lt;p&gt;Sorry, that page doesn&#39;t exist.&lt;/p&gt;"/>

I tried some alternate syntax, such as:

<Property Name="PageContent1">
    <![CDATA[<h1>Page Not Found</h1><p>Sorry, that page doesn't exist.</p>]]>
</Property>

but that didn't work either. The field PageContent1 is always empty, and I see no errors in the logs.

I only see this issue for HTML fields like PageContent1. I'm using the same technique to set the value of a Lookup Column and Note field on the page and have no problems there.

Is anybody using this technique to provision Publishing pages and populate them with content?

Thank you

share|improve this question
    
Is the Html field built in, or one you provisioned as part of a content type for a page layout? –  James Love Dec 6 '11 at 19:09
    
I believe it should render the content. I would suggest double check the field name, make sure you are using internal name and then delete the page and reactivate the feature. –  Ashish Patel Dec 6 '11 at 19:17
    
James, PageContent1 is an HTML field that's part of the content type associated with the page. –  George Durzi Dec 6 '11 at 22:02
    
Ashish, the page is created as part of a feature. –  George Durzi Dec 6 '11 at 22:18

3 Answers 3

up vote 4 down vote accepted

When provisioning Publishing Pages, you need to load an instance of the Template Redirection Page (found under SiteTemplates\SPS\default.aspx), but set the Url for the page to the name that you want to create, and set the properties such as content type and page layout in the normal way.

Have a look at this for an example: http://stefan-stanev-sharepoint-blog.blogspot.com/2010/07/provision-publishing-pages-in-sandbox.html

But modify the Feature Module to look like this:

<Module Name="MyPages" SetupPath="SiteTemplates\SPS" Url="Pages">
    <File Url="Page-Not-Found.aspx" Path="default.aspx" Type="GhostableInLibrary">
      <Property Name="Title" Value="Page Not Found" />
      <Property Name="ContentType" Value="My Content Type Name" />
      <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/MyPageLayout.aspx, My Page Layout Name" />
      <Property Name="PageContent1" Value="&lt;h1&gt;Page Not Found&lt;/h1&gt;&lt;p&gt;Sorry, that page doesn&#39;t exist.&lt;/p&gt;"/>
    </File>
  </Module>
share|improve this answer
    
James, let me try that. I'm using the Template Redirection page, but I actually have a copy of it in my feature. –  George Durzi Dec 6 '11 at 22:03
    
James, this worked great. Thank you. It's strange that it wasn't working before because I was using my own copy of the Template Redirection Page (which I now know that I don't need). Thanks again. –  George Durzi Dec 6 '11 at 22:58
    
It's more to do with where the Feature gets the file (see the SetupPath attribute of Module). For some reason it never likes it when you try and pick a custom template file. –  James Love Dec 7 '11 at 7:47

The common practice to place content on a published page is to use Content Editor Web Part. Look at this post how to configure provision in this case.

share|improve this answer
    
Alexander, this actually breaks content deployment because the CEWP injects absolute URLs into the content. –  George Durzi Dec 6 '11 at 22:00

If your trying to add content to a SharePoint content area then this article shows you how to add a web part to it, the code would only need adapting slightly to add content. http://blog.mastykarz.nl/programmatically-adding-web-parts-rich-content-sharepoint-2010/

share|improve this answer
    
Colin, this is actually different than what I need to do. In addition to automating provisioning my Publishing pages, I want to automate the process of provisioning the content within them. –  George Durzi Dec 6 '11 at 22:02

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.