hcwzwx 发表于 2015-9-25 08:27:03

Sharepoint 2010 自定义布局页

  这里主要介绍如何使用Sharepoint Designer自定义布局页,及如何使用Visual Studio 2010创建部署解决方案。
  1:创建内容类型
  1-1:首先我们使用VS2010 创建一个内容类型项目。   

  1-2:该内容类型继承“页面”内容类型,页面内容类型属于发布内容。

  1-3:我希望在页面上面显示一些“版权” ,“图像”等。所以需要为这些内容提供一个栏位来存醋。所以我们需要在这内容类型里面新增几个栏。代码如下:
<?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?>
<Elements xmlns=&quot;http://schemas.microsoft.com/sharepoint/&quot;>
<!-- Parent ContentType: 页面 (0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39) -->
<ContentType ID=&quot;0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900d9382e6c08b34b38af10610a206f51c1&quot;
Name=&quot;Ylsoft门户网站页面&quot;
Group=&quot;YLSoft Portal&quot;
Description=&quot;Ylsoft门户网站页面内容类型&quot;
Version=&quot;0&quot;>
<FieldRefs>
<FieldRef ID=&quot;{F55C4D88-1F2E-4ad9-AAA8-819AF4EE7EE8}&quot; Name=&quot;PublishingPageContent&quot; DisplayName=&quot;网页内容&quot;/>
<FieldRef ID=&quot;{3de94b06-4120-41a5-b907-88773e493458}&quot; Name=&quot;PublishingPageImage&quot; DisplayName=&quot;页面图像&quot; />
<FieldRef ID=&quot;{543BC2CF-1F30-488e-8F25-6FE3B689D9AC}&quot; Name=&quot;PublishingRollupImage&quot; DisplayName=&quot;滚动图像&quot; />
<FieldRef ID=&quot;{31E5E0E6-73C7-41BA-BFC8-7E43B454C1EB}&quot; Name=&quot;PublishingPageSideContent&quot; DisplayName=&quot;网页边栏内容&quot;/>
<FieldRef ID=&quot;{6f7a46dc-94e6-46b6-916b-cd05092e42ec}&quot; Name=&quot;PublishingPageAreaShow&quot; DisplayName=&quot;显示区域&quot;/>
<FieldRef ID=&quot;{FB0A88BB-8D83-4436-B650-2C14D1A2C1BC}&quot; Name=&quot;PublishingPageCopyRight&quot; DisplayName =&quot;版权&quot;/>
</FieldRefs>
</ContentType>
<Field ID=&quot;{31E5E0E6-73C7-41BA-BFC8-7E43B454C1EB}&quot;
Name=&quot;PublishingPageSideContent&quot;
StaticName=&quot;PublishingPageSideContent&quot;
SourceID=&quot;http://schemas.microsoft.com/sharepoint/v3&quot;
Group=&quot;YLSoft Portal&quot;
DisplayName=&quot;网页边栏内容&quot;
Type=&quot;HTML&quot;
Required=&quot;FALSE&quot;
Sealed=&quot;TRUE&quot;
RichText=&quot;TRUE&quot;
RichTextMode=&quot;FullHtml&quot; />
<Field ID=&quot;{FB0A88BB-8D83-4436-B650-2C14D1A2C1BC}&quot;
Name=&quot;PublishingPageCopyRight&quot;
DisplayName =&quot;版权&quot;
StaticName=&quot;PublishingPageCopyRight&quot;
SourceID=&quot;http://schemas.microsoft.com/sharepoint/v3&quot;
Group=&quot;YLSoft Portal&quot;
Type=&quot;HTML&quot;
Required=&quot;FALSE&quot;
Sealed=&quot;TRUE&quot;
RichText=&quot;TRUE&quot;
RichTextMode=&quot;FullHtml&quot; />
<Field Type=&quot;MultiChoice&quot;
DisplayName=&quot;显示区域&quot;
Required=&quot;FALSE&quot;
EnforceUniqueValues=&quot;FALSE&quot;
Indexed=&quot;FALSE&quot;
FillInChoice=&quot;FALSE&quot;
Group=&quot;YLSoft Portal&quot;
ID=&quot;{6f7a46dc-94e6-46b6-916b-cd05092e42ec}&quot;
SourceID=&quot;{f67bda5f-fa92-48f8-b1d5-0cfcf724358b}&quot;
StaticName=&quot;显示区域&quot;
Name=&quot;显示区域&quot;>
<Default>无</Default>
<CHOICES>
<CHOICE>无</CHOICE>
<CHOICE>网站导航</CHOICE>
<CHOICE>页眉导航</CHOICE>
<CHOICE>页脚导航</CHOICE>
</CHOICES>
</Field>
</Elements>

  然后我们发布此内容类型。

  2:使用Sharepoint Designer 2010创建布局页
  2-1:新建布局页
  进入Sharepoint Designer2010


  在新建界面,选择我们刚刚发布的内容类型。

  我们开始设计这个界面。主要是如何使用我们刚刚创建的那些栏。
  2-2:设计布局页
  布局页使用默认的母板页,母板页我已经做好,或则你就使用系统默认的母板页页可以。建好布局页,我们一般都需要对PlaceHolderMain的内容区域进行排版布局。

<table width=&quot;100%&quot; border=&quot;0&quot; align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>
<!-- 横幅banner开始-->
<tr>
<td>
</td>
</tr>
<!-- 横幅banner结束-->
<tr>
<td height=&quot;10&quot;></td>
</tr>
<tr>
<td style=&quot;text-align:center;&quot; align=&quot;center&quot;><table width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
<tr>
<!-- 位置提示开始-->
<td style=&quot;vertical-align:top; text-align:left; line-height:36px;&quot;>
</td>
<!-- 位置提示结束-->
<td width=&quot;10&quot; rowspan=&quot;2&quot; style=&quot;width:10px;&quot;>&nbsp;</td>
<td rowspan=&quot;2&quot;style=&quot;width:245px; vertical-align:top;&quot;>
<!--右边栏目开始-->
<div style=&quot;height:10px;&quot;></div>
<!--右边栏目结束-->
</td>
</tr>
<tr>
<td style=&quot;vertical-align:top; text-align:left;&quot;>
<!--文章内容表格开始-->
<table width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
<tr>
<td>
</td>
</tr>
</table>
<!--文章内容表格结束-->
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style=&quot;text-align:center; height:10px;&quot;></td>
</tr>
</table>
<table width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;10&quot; cellpadding=&quot;0&quot; style=&quot;border-top:#AACBEE 1px solid; background-image:url(_layouts/images/ylsoft/portal/10soft-bottom-bg.jpg);&quot;>
<tr>
<td align=&quot;center&quot;>
</td>
</tr>
</table>
  我就在PlaceHolderMain插入上面的表格。效果如下图。基本布局就这样。

  我们在第一行插入WEBPART

  在同一行,我们还想显示我们内容类型里面“页面图像”网站栏的内容。很简单,操作如图 :

  详细过程就不描述,其中还有一个服务器控件(Sharepoint)里面的EditModePanel也比较有用,这控件只会在编辑模式下才会显示。最后的布局如下:

HTML:


<%@ Page language=&quot;C#&quot;   Inherits=&quot;Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c&quot; meta:webpartpageexpansion=&quot;full&quot; meta:progid=&quot;SharePoint.WebPartPage.Document&quot;%>
<%@ Register Tagprefix=&quot;SharePointWebControls&quot; Namespace=&quot;Microsoft.SharePoint.WebControls&quot; Assembly=&quot;Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; %> <%@ Register Tagprefix=&quot;WebPartPages&quot; Namespace=&quot;Microsoft.SharePoint.WebPartPages&quot; Assembly=&quot;Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; %> <%@ Register Tagprefix=&quot;PublishingWebControls&quot; Namespace=&quot;Microsoft.SharePoint.Publishing.WebControls&quot; Assembly=&quot;Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; %> <%@ Register Tagprefix=&quot;PublishingNavigation&quot; Namespace=&quot;Microsoft.SharePoint.Publishing.Navigation&quot; Assembly=&quot;Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; %>
<asp:Content ContentPlaceholderID=&quot;PlaceHolderPageTitle&quot; runat=&quot;server&quot;>
<SharePointWebControls:FieldValue id=&quot;PageTitle&quot; FieldName=&quot;Title&quot; runat=&quot;server&quot;/>
</asp:Content>
<asp:Content ContentPlaceholderID=&quot;PlaceHolderMain&quot; runat=&quot;server&quot;>
<PublishingWebControls:editmodepanel runat=&quot;server&quot; id=&quot;editmodepanel1&quot;>
<SharePointWebControls:CheckBoxChoiceField FieldName=&quot;6f7a46dc-94e6-46b6-916b-cd05092e42ec&quot; runat=&quot;server&quot;>
</SharePointWebControls:CheckBoxChoiceField>
</PublishingWebControls:editmodepanel>
<asp:ScriptManagerProxy runat=&quot;server&quot; id=&quot;ScriptManagerProxy&quot;>
</asp:ScriptManagerProxy>
<table width=&quot;100%&quot; border=&quot;0&quot; align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>
<!-- 横幅banner开始-->
<tr>
<td>
<WebPartPages:WebPartZone runat=&quot;server&quot; Title=&quot;顶部&quot; ID=&quot;top&quot;><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone>
<PublishingWebControls:RichImageField FieldName=&quot;3de94b06-4120-41a5-b907-88773e493458&quot; runat=&quot;server&quot;></PublishingWebControls:RichImageField>
</td>
</tr>
<!-- 横幅banner结束-->
<tr>
<td height=&quot;10&quot;></td>
</tr>
<tr>
<td style=&quot;text-align:center;&quot; align=&quot;center&quot;><table width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
<tr>
<!-- 位置提示开始-->
<td style=&quot;vertical-align:top; text-align:left; line-height:36px;&quot;>
<asp:SiteMapPath
runat=&quot;server&quot;
SiteMapProviders=&quot;SPSiteMapProvider,SPXmlContentMapProvider&quot;
RenderCurrentNodeAsLink=&quot;false&quot;
NodeStyle-CssClass=&quot;breadcrumbNode&quot;
CurrentNodeStyle-CssClass=&quot;breadcrumbCurrentNode&quot;
RootNodeStyle-CssClass=&quot;breadcrumbRootNode&quot;
HideInteriorRootNodes=&quot;true&quot;
SkipLinkText=&quot;&quot;/>
</td>
<!-- 位置提示结束-->
<td width=&quot;10&quot; rowspan=&quot;2&quot; style=&quot;width:10px;&quot;>&nbsp;</td>
<td rowspan=&quot;2&quot;style=&quot;width:245px; vertical-align:top;&quot;>
<!--右边栏目开始-->
<WebPartPages:WebPartZone runat=&quot;server&quot; Title=&quot;右侧1&quot; ID=&quot;Righter1&quot;><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone>
<PublishingWebControls:RichHtmlField FieldName=&quot;31e5e0e6-73c7-41ba-bfc8-7e43b454c1eb&quot; runat=&quot;server&quot; id=&quot;RichHtmlField1&quot;>
</PublishingWebControls:RichHtmlField>
<WebPartPages:WebPartZone runat=&quot;server&quot; Title=&quot;右侧2&quot; ID=&quot;Righter2&quot;><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone>
<div style=&quot;height:10px;&quot;></div>
<PublishingWebControls:RichImageField FieldName=&quot;543bc2cf-1f30-488e-8f25-6fe3b689d9ac&quot; runat=&quot;server&quot; id=&quot;RichImageField1&quot;></PublishingWebControls:RichImageField>
<!--右边栏目结束-->
</td>
</tr>
<tr>
<td style=&quot;vertical-align:top; text-align:left;&quot;>
<PublishingWebControls:EditModePanel runat=server id=&quot;EditModePanel2&quot;>
<SharePointWebControls:TextField FieldName=&quot;fa564e0f-0c70-4ab9-b863-0177e6ddd247&quot; runat=&quot;server&quot; id=&quot;TextField1&quot;>
</SharePointWebControls:TextField>
</PublishingWebControls:EditModePanel>
<!--文章内容表格开始-->
<table width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
<tr>
<td>
<PublishingWebControls:RichHtmlField FieldName=&quot;f55c4d88-1f2e-4ad9-aaa8-819af4ee7ee8&quot; runat=&quot;server&quot;></PublishingWebControls:RichHtmlField>
</td>
</tr>
</table>
<!--文章内容表格结束-->
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style=&quot;text-align:center; height:10px;&quot;></td>
</tr>
</table>
<table width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;10&quot; cellpadding=&quot;0&quot; style=&quot;border-top:#AACBEE 1px solid; background-image:url(_layouts/images/ylsoft/portal/10soft-bottom-bg.jpg);&quot;>
<tr>
<td align=&quot;center&quot;>
<PublishingWebControls:RichHtmlField FieldName=&quot;fb0a88bb-8d83-4436-b650-2c14d1a2c1bc&quot; runat=&quot;server&quot;></PublishingWebControls:RichHtmlField>
</td>
</tr>
</table>
</asp:Content>
  3:利用VS2010发布布局页
  
  
  
  3-1:增加一个Empty Sharepoint Project项目

  3-2: 然后在这个项目增加一个Module

  把新增后的sample.txt文件删除。
  将刚刚在Sharepoint Dsigner做好的ylsoftportalcontentpage.aspx布局页拷贝到YLSoftPortalPageLayouts Module目录下。

  同时把布局页代码里面的meta:webpartpageexpansion=&quot;full&quot; meta:progid=&quot;SharePoint.WebPartPage.Document这段代码移除,如果没有移除,Sharepoint会认为这个布局页有定制过。
  接下来修改这个Elements.xml。

<?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?>
<Elements xmlns=&quot;http://schemas.microsoft.com/sharepoint/&quot;>
<Module Name=&quot;YLSoftPortalPageLayouts&quot; Url=&quot;_catalogs/masterpage&quot;>
<File Path=&quot;YLSoftPortalPageLayouts\ylsoftportalcontentpage.aspx&quot; Url=&quot;ylsoftportalcontentpage.aspx&quot; Type=&quot;GhostableInLibrary&quot;>
<Property Name=&quot;Title&quot; Value=&quot;YLSoft门户内容页面&quot; />
<Property Name=&quot;MasterPageDescription&quot; Value=&quot;YLSoft门户网站的内容页面布局&quot;/>
<Property Name=&quot;ContentType&quot; Value=&quot;$Resources:cmscore,contenttype_pagelayout_name;&quot; />
<Property Name=&quot;PublishingPreviewImage&quot; Value=&quot;~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/ylsoftportalcontent.png, ~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/ylsoftportalcontent.png&quot; />
<Property Name=&quot;PublishingAssociatedContentType&quot; Value=&quot;;#Ylsoft门户网站页面;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900d9382e6c08b34b38af10610a206f51c1;#&quot;/>
</File>
</Module>
</Elements>
  
  Url,指定我这个布局页存放的地址,这里我写的是_catalogs/masterpage,这个地址实际上就是母板页样式库(http://Server/_catalogs/masterpage/Forms/AllItems.aspx)
  Property元素制定了这个布局页的一些属性,也就是母板页样式库的一些栏位的字段。其中PublishingAssociatedContentType的值是我们刚刚创建的布局页内容类型。
  具体Module的帮助,可以访问:http://msdn.microsoft.com/en-us/library/ms453137.aspx。我们发布这个项目。你就可以在母板页样式库看到你所发布的这个母板页了。

页: [1]
查看完整版本: Sharepoint 2010 自定义布局页