3

I have created some page layouts with web part zones in visual studio and they work fine, however, I don't want to have to manually add web parts in the zones each time a new page is created using that layout.

I have in my elements file for the layouts:

<File Path="Masterpage\Department.aspx" Url="Department.aspx" Type="GhostableInLibrary">
    <Property Name="Title" Value="Department Layout" />
    <Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;" />
    <Property Name="PublishingPreviewImage" Value="~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/PreviewImage/PageLayoutIcon.png, ~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/PreviewImage/PageLayoutIcon.png" />
    <Property Name="PublishingAssociatedContentType" Value=";#$Resources:cmscore,Department Content Type;#0x01010007FF3E057FA8AB4AA42FCB67B453FFC100E214EEE741181F4E9F7ACC43278EE81100048d8f4ef5834fa2bcfdb8b0fac9a9c3;#"/>
    <AllUsersWebPart WebPartZoneID="BottomLeft" WebPartOrder="1">
      <![CDATA[              
        <?xml version="1.0" encoding="utf-8"?>
        <webParts>
          <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
            <metaData>
              <type name="Microsoft.SharePoint.WebPartPages.ContentEditorWebPart, Microsoft.SharePoint" />
              <importErrorMessage>$Resources:core,ImportErrorMessage;</importErrorMessage>
            </metaData>
            <data>
              <properties>
                <property name="Title" type="string">test</property>
                <property name="Description" type="string">test</property>
              </properties>
            </data>
          </webPart>
        </webParts>
        ]]>
    </AllUsersWebPart>    
  </File>

and on the layout the zone:

<WebPartPages:WebPartZone runat="server" Title="loc:Bottom Left" ID="BottomLeft" FrameType="None"></WebPartPages:WebPartZone>

but when I deploy this and add a new page using the layout the zone is empty, no web part there so what am I missing here?

Thanks in advance.

Edit: so when I delete the layout and redeploy and have a look at it with SPD the zone gets populated but it doesn't look right and when I go to a page and try to use that layout I get an error:

in the web part zone:

<webParts __WebPartId="{D25AA5E4-EEA1-4709-830F-9DCE18A11E18}" __MarkupType="xmlmarkup" WebPart="true">
          <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
            <metaData>
               <type name="Microsoft.SharePoint.WebPartPages.ContentEditorWebPart, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
              <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
             </metaData><data><properties><property name="Title" type="string">test</property> <property name="Description" type="string">test</property> </properties></data></webPart></webParts>

error:

[MissingMethodException: No parameterless constructor defined for this object.]
   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) +0
   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) +146
   System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) +298
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +79
   Microsoft.SharePoint.WebPartPages.SPWebPartReflectionHelper.GetDefaultControl(Type controlType) +140
   Microsoft.SharePoint.WebPartPages.BinaryWebPartSerializer.GetDefaultControl() +38
   Microsoft.SharePoint.WebPartPages.BinaryWebPartSerializer.Serialize(PersonalizationScope scope) +832
   Microsoft.SharePoint.WebPartPages.BinaryWebPartSerializer.get_Links() +46
   Microsoft.SharePoint.WebPartPages.SPWebPartManager.AddWebPartToStore(WebPart webPart, Int32 viewId, String viewGuid) +532
   Microsoft.SharePoint.WebPartPages.SPWebPartManager.AddWebPartInternal(SPSupersetWebPart superset, Boolean throwIfLocked) +233
   Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager.AddWebPartInternal(WebPart webPart, String zoneId, Int32 zoneIndex, Boolean throwIfLocked) +116
   Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager.AddWebPart(WebPart webPart, String zoneId, Int32 zoneIndex) +37
   Microsoft.SharePoint.Publishing.PublishingPage.CopyAllWebParts(String destinationPageUrlServerRelative, SPWeb destinationPageWeb, String sourcePageUrlServerRelative, SPWeb sourcePageWeb, Boolean shouldOverwriteDestinationWebParts) +600
   Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.PageLayoutAction.changePageLayout(String newPageLayoutUrl) +480
   Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.PageLayoutAction.RaisePostBackEvent(String eventArgument) +135
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981

3 Answers 3

2

Try this:

            <![CDATA[<WebPart xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/WebPart/v2">
  <Title>Content Editor Testing</Title>
  <FrameType>Default</FrameType>
  <Description>Allows authors to enter rich text content.</Description>
  <IsIncluded>true</IsIncluded>
  <ZoneID>Header</ZoneID>
  <PartOrder>0</PartOrder>
  <FrameState>Normal</FrameState>
  <Height />
  <Width />
  <AllowRemove>true</AllowRemove>
  <AllowZoneChange>true</AllowZoneChange>
  <AllowMinimize>true</AllowMinimize>
  <AllowConnect>true</AllowConnect>
  <AllowEdit>true</AllowEdit>
  <AllowHide>true</AllowHide>
  <IsVisible>true</IsVisible>
  <DetailLink />
  <HelpLink />
  <HelpMode>Modeless</HelpMode>
  <Dir>Default</Dir>
  <PartImageSmall />
  <MissingAssembly>Cannot import this Web Part.</MissingAssembly>
  <PartImageLarge>/_layouts/images/mscontl.gif</PartImageLarge>
  <IsIncludedFilter />
  <Assembly>Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
  <TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>
  <ContentLink xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
  <Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
  <PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
</WebPart>]]>
6
  • same result unfortunately, no web part is added to the layout
    – john
    Mar 23, 2012 at 5:20
  • Can you try deleting the existing page layout from the gallery and re-activate your feature. Also after you create a new page, append ?contents=1 to the url to see list of webparts on the page.
    – sssreddy
    Mar 23, 2012 at 15:42
  • Hi sssreddy, I updated my question a bit.
    – john
    Mar 26, 2012 at 6:10
  • Was able to deploy page layout using above xml. see edited ans.
    – sssreddy
    Mar 26, 2012 at 17:27
  • 1
    I want to do something similar to the above, except I would like my ContentEditorWebPart to deploy with some HTML already in it. I was able to arrive at the above XML snippet on my own by exporting to a .dwp file. The <Content ...> node in my scenario has it's own embedded CDATA section where my HTML is seeded. When I put together my Visual Studio module file, it looks like I cannot nest a CDATA inside the larger CDATA section. Am I right?
    – bkwdesign
    Nov 2, 2012 at 15:32
2
  <AllUsersWebPart WebPartZoneID="Middle" WebPartOrder="3">
    <![CDATA[
     <?xml version="1.0" encoding="utf-8"?>
     <WebPart xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/WebPart/v2">
      <Title>Middle web part</Title>
      <FrameType>None</FrameType>
      <Description>Allows authors to enter rich text content.</Description>
      <IsIncluded>true</IsIncluded>
      <ZoneID>Middle</ZoneID>
      <PartOrder>0</PartOrder>
      <FrameState>Normal</FrameState>
      <Height />
      <Width />
      <AllowRemove>true</AllowRemove>
      <AllowZoneChange>true</AllowZoneChange>
      <AllowMinimize>true</AllowMinimize>
      <AllowConnect>true</AllowConnect>
      <AllowEdit>true</AllowEdit>
      <AllowHide>true</AllowHide>
      <IsVisible>true</IsVisible>
      <DetailLink />
      <HelpLink />
      <HelpMode>Modeless</HelpMode>
      <Dir>Default</Dir>
      <PartImageSmall />
      <MissingAssembly>Cannot import this Web Part.</MissingAssembly>
      <PartImageLarge>/_layouts/15/images/mscontl.gif</PartImageLarge>
      <IsIncludedFilter />
      <Assembly>Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
      <TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>
      <ContentLink xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor">/Style Library/Compliance/Html/Middle.txt</ContentLink>
      <Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
      <PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
      </WebPart>
    ]]>
  </AllUsersWebPart>
0
0

Do you have any uint type property in your web part? Please check that. If any of uint type property exist in your webpart code, then change the type from uint to int.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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