您也可以将您的页面布局作为单个功能部署,而不是创建整个网站定义。这样,您可以将页面布局部署到任何SharePoint发布网站。如果您使用VS 2010,请从SharePoint模块项目开始。将您的布局aspx文件添加到项目中。修改elements.xml文件以类似于此:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="Page Layouts" Url="_catalogs/masterpage" RootWebOnly="True">
<File Path="Page Layouts\Layout1.aspx" Url="Layout1.aspx" Type="GhostableInLibrary" IgnoreIfAlreadyExists="True">
<Property Name="Title" Value="My Layout 1" />
<Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;" />
</File>
</Module>
</Elements>
这将部署您的布局并使其可用于新的发布页面。现在,为了让webpart在新页面中实例化,可以使用webpart定义修改<File>
元素。例如,我可以定义一个内容编辑器web部件将在1区新页面创建这样的:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="Page Layouts" Url="_catalogs/masterpage" RootWebOnly="True">
<File Path="Page Layouts\Layout1.aspx" Url="Layout1.aspx" Type="GhostableInLibrary" IgnoreIfAlreadyExists="True">
<Property Name="Title" Value="My Layout 1" />
<Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;" />
<AllUsersWebPart WebPartZoneID="Zone1" WebPartOrder="1">
<![CDATA[
<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
<Assembly>Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
<TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>
<Title>Content Editor</Title>
<FrameType>Default</FrameType>
<FrameState>Normal</FrameState>
<Description></Description>
<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/homepage.gif</PartImageLarge>
<IsIncludedFilter />
<ExportControlledProperties>true</ExportControlledProperties>
<ContentLink xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
<Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor">
</Content>
<PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
</WebPart>
]]>
</AllUsersWebPart>
</File>
</Module>
</Elements>
这应该是比创造一个全新的网站定义更加实用。希望这可以帮助。
请您指点我一个示例吗?我不太喜欢。另外,我有5种不同的页面布局,它们会有不同的应该可编辑的Web部件组合。 – ScottE 2010-12-13 12:15:47
http://msdn.microsoft.com/en-us/vcsharp/ff623012.aspx视频链接 – 2010-12-13 13:03:25
谢谢,但这对我真的很有帮助。用户如何移除该Web部件或更改其属性? – ScottE 2010-12-13 13:39:04