Sharepoint开发之旅(2):SiteDefinition自定义母版页
初次学习sharepoint,本文采用的方法很可能不是最好的,如果您有更好的办法,请在回复中说明,谢谢.
- 新建一个SiteDefinition (Farm),并修改webtemp文件中Template的ID(大于10000的任何一个数字,并且不可和已有的SiteDefinition重复)
- 在解决方案资源管理器中(Ctrl+W,S)展开SiteDenfinition节点,右键单击SiteDefinition节点,Add->Add New Item 在对话框中右侧选择Visual C# –> Web,右侧选择HTML Page对话框下面的Name更改为 MyMaster.master(这个名称可以自定义).
- 更改刚刚加入的MyMaster.master的内容为:
<%@ Master Language="C#" %> <%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint" %> <%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %> <%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register TagPrefix="wssuc" TagName="Welcome" Src="~/_controltemplates/Welcome.ascx" %> <%@ Register TagPrefix="wssuc" TagName="MUISelector" Src="~/_controltemplates/MUISelector.ascx" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html id="Html1" lang="<%$Resources:wss,language_value%>" xmlns:o="urn:schemas-microsoft-com:office:office" runat="server" dir="<%$Resources:wss,multipages_direction_dir_value%>"> <head id="Head1" runat="server"> <meta http-equiv="X-UA-Compatible" content="IE=8" /> <meta name="GENERATOR" content="Microsoft SharePoint" /> <meta name="progid" content="SharePoint.WebPartPage.Document" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Expires" content="0" /> <title>master-><asp:ContentPlaceHolder ID="PlaceHolderPageTitle" runat="server"> </asp:ContentPlaceHolder> </title> </head> <body> <WebPartPages:WebPartManager ID="WPManager" runat="server" /> This is a master page! <asp:ContentPlaceHolder ID="PlaceHolderMain" runat="server"> </asp:ContentPlaceHolder> </body> </html> 这是一个简单的母版页,简单到基本上啥也没有.
-
更改onet.xml文件.
打开onet.xml文件,你会发现Project –> Modules –> Module[Name=DefaultBlank] 节点下已经包含了我们刚刚添加的master文件MyMaster.master
我们在Project –> Modules 下添加一个 Module[Name=MasterPage]并设置其Url为_catalogs/masterpage
将Module[Name=DefaultBlank]节点下的File[Url=default.aspx]节点移动到Module[Name=MasterPage]节点下.
在Project->Configuration->Modules中添加我们刚刚新建的Module[Name=MasterPage]节点
修改后的onet.xml文件大致为:<?xml version="1.0" encoding="utf-8"?> <Project Title="ZhuiSha.SiteDefinition" Revision="2" ListDir="" xmlns:ows="Microsoft SharePoint" xmlns="http://schemas.microsoft.com/sharepoint/"> <NavBars> </NavBars> <Configurations> <Configuration ID="0" Name="ZhuiSha.SiteDefinition" CustomMasterUrl="_catalogs/masterpage/MyMaster.master"> <Lists/> <SiteFeatures> </SiteFeatures> <WebFeatures> </WebFeatures> <Modules> <Module Name="MasterPage" /> <Module Name="DefaultBlank" /> </Modules> </Configuration> </Configurations> <Modules> <Module Name="MasterPage" Url="_catalogs/masterpage"> <File Path="MyMaster.master" Url="MyMaster.master" /> </Module> <Module Name="DefaultBlank" Url="" Path=""> <File Url="default.aspx" Path="default.aspx"> </File> </Module> </Modules> </Project>
-
修改SiteDefinition –> default.aspx 为:
<%@ Page language="C#" MasterPageFile="~masterurl/custom.master" Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage,Microsoft.SharePoint,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %> <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint" %> <%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %> <%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <asp:Content ID="Content1" ContentPlaceHolderId="PlaceHolderMain" runat="server"> <h1> Welcome to the custom site MySiteDefinition </h1> <WebPartPages:WebPartZone id="Zoon1" runat="server" title="Zoon1"><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone> </asp:Content>
-
发布(右键点项目节点,选择Deploy)
-
新建一个Site Collection 并选择模板为ZhuiSha.SiteDefinition.新建完成后打开新建的网站,即可看到效果.
-
再次声明,初学SharePoint,希望懂行的多指教.PS:SharePoint难道这么多的东西都需要猜么,太没意思了…