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