gblf 发表于 2015-9-28 12:43:14

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=&quot;C#&quot; %>
<%@ Register TagPrefix=&quot;SharePoint&quot; Namespace=&quot;Microsoft.SharePoint.WebControls&quot;
Assembly=&quot;Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; %>
<%@ Register TagPrefix=&quot;Utilities&quot; Namespace=&quot;Microsoft.SharePoint.Utilities&quot; Assembly=&quot;Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; %>
<%@ Import Namespace=&quot;Microsoft.SharePoint&quot; %>
<%@ Assembly Name=&quot;Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; %>
<%@ Import Namespace=&quot;Microsoft.SharePoint.ApplicationPages&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;wssuc&quot; TagName=&quot;Welcome&quot; Src=&quot;~/_controltemplates/Welcome.ascx&quot; %>
<%@ Register TagPrefix=&quot;wssuc&quot; TagName=&quot;MUISelector&quot; Src=&quot;~/_controltemplates/MUISelector.ascx&quot; %>
<!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;
&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;>
<html id=&quot;Html1&quot; lang=&quot;<%$Resources:wss,language_value%>&quot; xmlns:o=&quot;urn:schemas-microsoft-com:office:office&quot;
runat=&quot;server&quot; dir=&quot;<%$Resources:wss,multipages_direction_dir_value%>&quot;>
<head id=&quot;Head1&quot; runat=&quot;server&quot;>
<meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=8&quot; />
<meta name=&quot;GENERATOR&quot; content=&quot;Microsoft SharePoint&quot; />
<meta name=&quot;progid&quot; content=&quot;SharePoint.WebPartPage.Document&quot; />
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; />
<meta http-equiv=&quot;Expires&quot; content=&quot;0&quot; />
<title>master-><asp:ContentPlaceHolder ID=&quot;PlaceHolderPageTitle&quot; runat=&quot;server&quot;>
</asp:ContentPlaceHolder>
</title>
</head>
<body>
<WebPartPages:WebPartManager ID=&quot;WPManager&quot; runat=&quot;server&quot; />
This is a master page!
<asp:ContentPlaceHolder ID=&quot;PlaceHolderMain&quot; runat=&quot;server&quot;>
</asp:ContentPlaceHolder>
</body>
</html>
这是一个简单的母版页,简单到基本上啥也没有.


更改onet.xml文件.
打开onet.xml文件,你会发现Project –> Modules –> Module 节点下已经包含了我们刚刚添加的master文件MyMaster.master
我们在Project –> Modules 下添加一个 Module并设置其Url为_catalogs/masterpage
将Module节点下的File节点移动到Module节点下.
在Project->Configuration->Modules中添加我们刚刚新建的Module节点
修改后的onet.xml文件大致为:
<?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?>
<Project Title=&quot;ZhuiSha.SiteDefinition&quot; Revision=&quot;2&quot; ListDir=&quot;&quot; xmlns:ows=&quot;Microsoft SharePoint&quot; xmlns=&quot;http://schemas.microsoft.com/sharepoint/&quot;>
<NavBars>
</NavBars>
<Configurations>
<Configuration ID=&quot;0&quot; Name=&quot;ZhuiSha.SiteDefinition&quot; CustomMasterUrl=&quot;_catalogs/masterpage/MyMaster.master&quot;>
<Lists/>
<SiteFeatures>
</SiteFeatures>
<WebFeatures>
</WebFeatures>
<Modules>
<Module Name=&quot;MasterPage&quot; />
<Module Name=&quot;DefaultBlank&quot; />
</Modules>
</Configuration>
</Configurations>
<Modules>
<Module Name=&quot;MasterPage&quot; Url=&quot;_catalogs/masterpage&quot;>
<File Path=&quot;MyMaster.master&quot; Url=&quot;MyMaster.master&quot; />
</Module>
<Module Name=&quot;DefaultBlank&quot; Url=&quot;&quot; Path=&quot;&quot;>
<File Url=&quot;default.aspx&quot; Path=&quot;default.aspx&quot;>
</File>
</Module>
</Modules>
</Project>


修改SiteDefinition –> default.aspx 为:
<%@ Page language=&quot;C#&quot; MasterPageFile=&quot;~masterurl/custom.master&quot; Inherits=&quot;Microsoft.SharePoint.WebPartPages.WebPartPage,Microsoft.SharePoint,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c&quot;%>
<%@ Register Tagprefix=&quot;SharePoint&quot; Namespace=&quot;Microsoft.SharePoint.WebControls&quot; Assembly=&quot;Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; %>
<%@ Register Tagprefix=&quot;Utilities&quot; Namespace=&quot;Microsoft.SharePoint.Utilities&quot; Assembly=&quot;Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; %>
<%@ Register Tagprefix=&quot;asp&quot; Namespace=&quot;System.Web.UI&quot; Assembly=&quot;System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&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; %>
<%@ Import Namespace=&quot;Microsoft.SharePoint&quot; %>
<%@ Import Namespace=&quot;Microsoft.SharePoint.ApplicationPages&quot; %>
<%@ Assembly Name=&quot;Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; %>

<asp:Content ID=&quot;Content1&quot; ContentPlaceHolderId=&quot;PlaceHolderMain&quot; runat=&quot;server&quot;>
<h1>
Welcome to the custom site
MySiteDefinition
</h1>
<WebPartPages:WebPartZone id=&quot;Zoon1&quot; runat=&quot;server&quot; title=&quot;Zoon1&quot;><ZoneTemplate></ZoneTemplate></WebPartPages:WebPartZone>
</asp:Content>



发布(右键点项目节点,选择Deploy)


新建一个Site Collection 并选择模板为ZhuiSha.SiteDefinition.新建完成后打开新建的网站,即可看到效果.


再次声明,初学SharePoint,希望懂行的多指教.PS:SharePoint难道这么多的东西都需要猜么,太没意思了…
页: [1]
查看完整版本: Sharepoint开发之旅(2):SiteDefinition自定义母版页