创建最精简的Sharepoint母板页
做Sharepoint网站的时候,经常会有要弹出空白页面的需求,而要满足这样的需求,必须另外新建一个母板页。如何开发一个最精简的母板页呢,下面我根据我的项目经验谈谈我的做法。
step 1:用Designer 2007新建母板页类型页面,如下图:
Step 2:以代码视图打开新建的母板页面,Copy下面的代码,覆盖生成的代码
Code
1<%-- Identifies this page as a .master page written in Microsoft Visual C# and registers tag prefixes, namespaces, assemblies, and controls. --%>
2<%@ Master language="C#" %>
3<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4<%@ Import Namespace="Microsoft.SharePoint" %>
5<%@ Register Tagprefix="SPSWC" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
6<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
7<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
8<%@ Register Tagprefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
9<%@ Register Tagprefix="PublishingNavigation" Namespace="Microsoft.SharePoint.Publishing.Navigation" Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
10<%@ Register TagPrefix="wssuc" TagName="Welcome" src="~/_controltemplates/Welcome.ascx" %>
11<%@ Register TagPrefix="wssuc" TagName="DesignModeConsole" src="~/_controltemplates/DesignModeConsole.ascx" %>
12<%@ Register TagPrefix="PublishingVariations" TagName="VariationsLabelMenu" src="~/_controltemplates/VariationsLabelMenu.ascx" %>
13<%@ Register Tagprefix="PublishingConsole" TagName="Console" src="~/_controltemplates/PublishingConsole.ascx" %>
14<%@ Register TagPrefix="PublishingSiteAction" TagName="SiteActionMenu" src="~/_controltemplates/PublishingActionMenu.ascx" %>
15<%-- Uses the Microsoft Office namespace and schema. --%>
16<html>
17 <WebPartPages:SPWebPartManager runat="server"/>
18 <SharePoint:RobotsMetaTag runat="server"/>
19
20 <%-- The head section includes a content placeholder for the page title and links to CSS and ECMAScript (JScript, JavaScript) files that run on the server. --%>
21 <head runat="server">
22 <asp:ContentPlaceHolder runat="server" id="head">
23 <title>
24 <asp:ContentPlaceHolder id="PlaceHolderPageTitle" runat="server" />
25 </title>
26 </asp:ContentPlaceHolder>
27 <Sharepoint:CssLink runat="server"/>
28 <asp:ContentPlaceHolder id="PlaceHolderAdditionalPageHead" runat="server" />
29 </head>
30
31 <%-- When loading the body of the .master page, SharePoint Server 2007 also loads the SpBodyOnLoadWrapper class. This class handles .js calls for the master page. --%>
32 <body onload="javascript:_spBodyOnLoadWrapper();">
33 <%-- The SPWebPartManager manages all of the Web part controls, functionality, and events that occur on a Web page. --%>
34 <form runat="server" onsubmit="return _spFormOnSubmitWrapper();">
35 <wssuc:Welcome id="explitLogout" runat="server"/>
36 <PublishingSiteAction:SiteActionMenu runat="server"/>
37 <PublishingWebControls:AuthoringContainer id="authoringcontrols" runat="server">
38 <PublishingConsole:Console runat="server" />
39 </PublishingWebControls:AuthoringContainer>
40 <%-- The PlaceHolderMain content placeholder defines where to place the page content for all the content from the page layout. The page layout can overwrite any content placeholder from the master page. Example: The PlaceHolderLeftNavBar can overwrite the left navigation bar. --%>
41 <asp:ContentPlaceHolder id="PlaceHolderMain" runat="server" />
42 <asp:Panel visible="false" runat="server">
43 <%-- These ContentPlaceHolders ensure all default SharePoint Server pages render with this master page. If the system master page is set to any default master page, the only content placeholders required are those that are overridden by your page layouts. --%>
44<asp:ContentPlaceHolder id="PlaceHolderSearchArea" runat="server"/>
45<asp:ContentPlaceHolder id="PlaceHolderTitleBreadcrumb" runat="server"/>
46<asp:ContentPlaceHolder id="PlaceHolderPageTitleInTitleArea" runat="server"/>
47<asp:ContentPlaceHolder id="PlaceHolderLeftNavBar" runat="server"/>
48<asp:ContentPlaceHolder ID="PlaceHolderPageImage" runat="server"/>
49<asp:ContentPlaceHolder ID="PlaceHolderBodyLeftBorder" runat="server"/>
50<asp:ContentPlaceHolder ID="PlaceHolderNavSpacer" runat="server"/>
51<asp:ContentPlaceHolder ID="PlaceHolderTitleLeftBorder" runat="server"/>
52<asp:ContentPlaceHolder ID="PlaceHolderTitleAreaSeparator" runat="server"/>
53<asp:ContentPlaceHolder ID="PlaceHolderMiniConsole" runat="server"/>
54<asp:ContentPlaceHolder id="PlaceHolderCalendarNavigator" runat ="server" />
55<asp:ContentPlaceHolder id="PlaceHolderLeftActions" runat ="server"/>
56<asp:ContentPlaceHolder id="PlaceHolderPageDescription" runat ="server"/>
57<asp:ContentPlaceHolder id="PlaceHolderBodyAreaClass" runat ="server"/>
58<asp:ContentPlaceHolder id="PlaceHolderTitleAreaClass" runat ="server"/>
59<asp:ContentPlaceHolder id="PlaceHolderBodyRightMargin" runat="server" />
60</asp:Panel>
61 </form>
62 </body>
63</html>
64
1<%-- Identifies this page as a .master page written in Microsoft Visual C# and registers tag prefixes, namespaces, assemblies, and controls. --%>
2<%@ Master language="C#" %>
3<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4<%@ Import Namespace="Microsoft.SharePoint" %>
5<%@ Register Tagprefix="SPSWC" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
6<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
7<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
8<%@ Register Tagprefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
9<%@ Register Tagprefix="PublishingNavigation" Namespace="Microsoft.SharePoint.Publishing.Navigation" Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
10<%@ Register TagPrefix="wssuc" TagName="Welcome" src="~/_controltemplates/Welcome.ascx" %>
11<%@ Register TagPrefix="wssuc" TagName="DesignModeConsole" src="~/_controltemplates/DesignModeConsole.ascx" %>
12<%@ Register TagPrefix="PublishingVariations" TagName="VariationsLabelMenu" src="~/_controltemplates/VariationsLabelMenu.ascx" %>
13<%@ Register Tagprefix="PublishingConsole" TagName="Console" src="~/_controltemplates/PublishingConsole.ascx" %>
14<%@ Register TagPrefix="PublishingSiteAction" TagName="SiteActionMenu" src="~/_controltemplates/PublishingActionMenu.ascx" %>
15<%-- Uses the Microsoft Office namespace and schema. --%>
16<html>
17 <WebPartPages:SPWebPartManager runat="server"/>
18 <SharePoint:RobotsMetaTag runat="server"/>
19
20 <%-- The head section includes a content placeholder for the page title and links to CSS and ECMAScript (JScript, JavaScript) files that run on the server. --%>
21 <head runat="server">
22 <asp:ContentPlaceHolder runat="server" id="head">
23 <title>
24 <asp:ContentPlaceHolder id="PlaceHolderPageTitle" runat="server" />
25 </title>
26 </asp:ContentPlaceHolder>
27 <Sharepoint:CssLink runat="server"/>
28 <asp:ContentPlaceHolder id="PlaceHolderAdditionalPageHead" runat="server" />
29 </head>
30
31 <%-- When loading the body of the .master page, SharePoint Server 2007 also loads the SpBodyOnLoadWrapper class. This class handles .js calls for the master page. --%>
32 <body onload="javascript:_spBodyOnLoadWrapper();">
33 <%-- The SPWebPartManager manages all of the Web part controls, functionality, and events that occur on a Web page. --%>
34 <form runat="server" onsubmit="return _spFormOnSubmitWrapper();">
35 <wssuc:Welcome id="explitLogout" runat="server"/>
36 <PublishingSiteAction:SiteActionMenu runat="server"/>
37 <PublishingWebControls:AuthoringContainer id="authoringcontrols" runat="server">
38 <PublishingConsole:Console runat="server" />
39 </PublishingWebControls:AuthoringContainer>
40 <%-- The PlaceHolderMain content placeholder defines where to place the page content for all the content from the page layout. The page layout can overwrite any content placeholder from the master page. Example: The PlaceHolderLeftNavBar can overwrite the left navigation bar. --%>
41 <asp:ContentPlaceHolder id="PlaceHolderMain" runat="server" />
42 <asp:Panel visible="false" runat="server">
43 <%-- These ContentPlaceHolders ensure all default SharePoint Server pages render with this master page. If the system master page is set to any default master page, the only content placeholders required are those that are overridden by your page layouts. --%>
44<asp:ContentPlaceHolder id="PlaceHolderSearchArea" runat="server"/>
45<asp:ContentPlaceHolder id="PlaceHolderTitleBreadcrumb" runat="server"/>
46<asp:ContentPlaceHolder id="PlaceHolderPageTitleInTitleArea" runat="server"/>
47<asp:ContentPlaceHolder id="PlaceHolderLeftNavBar" runat="server"/>
48<asp:ContentPlaceHolder ID="PlaceHolderPageImage" runat="server"/>
49<asp:ContentPlaceHolder ID="PlaceHolderBodyLeftBorder" runat="server"/>
50<asp:ContentPlaceHolder ID="PlaceHolderNavSpacer" runat="server"/>
51<asp:ContentPlaceHolder ID="PlaceHolderTitleLeftBorder" runat="server"/>
52<asp:ContentPlaceHolder ID="PlaceHolderTitleAreaSeparator" runat="server"/>
53<asp:ContentPlaceHolder ID="PlaceHolderMiniConsole" runat="server"/>
54<asp:ContentPlaceHolder id="PlaceHolderCalendarNavigator" runat ="server" />
55<asp:ContentPlaceHolder id="PlaceHolderLeftActions" runat ="server"/>
56<asp:ContentPlaceHolder id="PlaceHolderPageDescription" runat ="server"/>
57<asp:ContentPlaceHolder id="PlaceHolderBodyAreaClass" runat ="server"/>
58<asp:ContentPlaceHolder id="PlaceHolderTitleAreaClass" runat ="server"/>
59<asp:ContentPlaceHolder id="PlaceHolderBodyRightMargin" runat="server" />
60</asp:Panel>
61 </form>
62 </body>
63</html>
64
Step 3:保存页面,命名你的自定义母板页名称,保存位置为你的网站集中的masterpage库(/_catalogs/masterpage)。示例代码:
Code
1 <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
2 <%@ Import Namespace="System.Web.UI.WebControls.WebParts" %>
3 <asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">
4 <table cellpadding="0" cellspacing="0" border="0" align="center" width="780px">
5 <tr>
6 <td width="780px">
7 <WebPartPages:WebPartZone runat="server" Title="IndentityDetailInfo" ID="Left"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone>
8 </td>
9 </tr>
10 </table>
11 </asp:Content>
1 <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
2 <%@ Import Namespace="System.Web.UI.WebControls.WebParts" %>
3 <asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">
4 <table cellpadding="0" cellspacing="0" border="0" align="center" width="780px">
5 <tr>
6 <td width="780px">
7 <WebPartPages:WebPartZone runat="server" Title="IndentityDetailInfo" ID="Left"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone>
8 </td>
9 </tr>
10 </table>
11 </asp:Content>
Step 4:然后就可以右键点击你新建好的母板页,选择“根据母板页新建”项新建页面就可以了。但记住一点,新建的页面必须自己手动书写布局,千万不要忘记添加WebpartZone项,要不然你新建的页面就无法编辑添加Webpart了。
参考资料:Microsoft Office sharepoint server 2007 sdk ——>How to:Create a Minimal Master Page.