Sharepoint開發之旅(2):SiteDefinition自訂主版頁面

來源:互聯網
上載者:User

初次學習sharepoint,本文採用的方法很可能不是最好的,如果您有更好的辦法,請在回複中說明,謝謝.

  1. 建立一個SiteDefinition (Farm),並修改webtemp檔案中Template的ID(大於10000的任何一個數字,並且不可和已有的SiteDefinition重複)
  2. 在方案總管中(Ctrl+W,S)展開SiteDenfinition節點,按右鍵SiteDefinition節點,Add->Add New Item 在對話方塊中右側選擇Visual C# –> Web,右側選擇HTML Page對話方塊下面的Name更改為 MyMaster.master(這個名稱可以自訂).
  3. 更改剛剛加入的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>

    這是一個簡單的主版頁面,簡單到基本上啥也沒有.

  4. 更改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>

  5. 修改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>

  6. 發布(右鍵點項目節點,選擇Deploy)
  7. 建立一個Site Collection 並選擇模板為ZhuiSha.SiteDefinition.建立完成後開啟建立的網站,即可看到效果.
  8. 再次聲明,初學SharePoint,希望懂行的多指教.PS:SharePoint難道這麼多的東西都需要猜麼,太沒意思了…

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.