天天看點

如何在SharePoint中建立Custom Master Page1. 安裝Features2. 自定義模闆3. 自定義布局頁面4. 上傳檔案并更改設定5. 建立測試頁面6. 釋出内容

SharePoint中有許多自帶的模闆頁,但有時候不能滿足我們的需要。那麼怎麼辦呢?SharePoint提供自定義模闆功能,下面我們來看看一個簡單自定義模闆是怎麼實作的。

1. 安裝Features

要使用自定義模闆功能,首先需要給自己的站點開通釋出自定義模闆的Feature。

第一步:Site Actions --> Site Settings --> Site Collection Administration --> Site collection features --> Activate "Office SharePoint Server Publishing Infrastructure"。

第二步:Site Actions --> Site Settings --> Site Administration --> Site features --> Activate "Office SharePoint Server Publishing"。

這個時候,你可以在Site Settings --> Galleries下面看到Master pages and page layouts,點進去,你可以Upload你自定義的Master pages和Page layouts。

2. 自定義模闆

建立一個MySite.Master檔案,在Master模闆檔案頭部包含下面代碼。

?

1 2 3

<%@ Master Language="C#" %>

<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

在head中添加CssLink控件。

?

1

<

SharePoint:CssLink

runat

=

"server"

/>

在form中添加SPWebPartManager控件和ContentPlaceHolder控件。

?

1 2

<

WebPartPages:SPWebPartManager

runat

=

"server"

/>

<

asp:ContentPlaceHolder

ID

=

"PlaceHolderMain"

runat

=

"server"

/>

一個簡單模闆頁已經建立成功了。

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

<%@ Master Language="C#" %>

<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<

html

xmlns

=

"http://www.w3.org/1999/xhtml"

>

<

head

runat

=

"server"

>

<

title

>My Site</

title

>

<

SharePoint:CssLink

runat

=

"server"

/>

</

head

>

<

body

>

<

form

runat

=

"server"

>

<

WebPartPages:SPWebPartManager

runat

=

"server"

/>

<

div

id

=

"wrapper"

>

<

div

id

=

"header"

style

=

"background-color:Gray"

>

<

h1

>My Site</

h1

>

</

div

>

<

div

id

=

"content"

>

<

asp:ContentPlaceHolder

ID

=

"PlaceHolderMain"

runat

=

"server"

/>

</

div

>

<

div

id

=

"footer"

style

=

"background-color:Lime"

>

Copyright © 2010 known

</

div

>

</

div

>

</

form

>

</

body

>

</

html

>

3. 自定義布局頁面

建立一個MyPage.aspx檔案,在自定義頁面檔案頭部添加一下代碼。

?

1 2

<%@ Page Language="C#" MasterPageFile="/_catalogs/masterpage/MySite.Master" Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

在Content控件中添加WebPartZone控件。

?

1 2 3 4 5 6 7 8 9 10 11 12

<

asp:Content

ContentPlaceHolderID

=

"PlaceHolderMain"

runat

=

"server"

>

<

table

width

=

"100%"

>

<

tr

>

<

td

width

=

"70%"

>

<

WebPartPages:WebPartZone

ID

=

"LeftRow"

runat

=

"server"

Title

=

"Left Content"

/>

</

td

>

<

td

>

<

WebPartPages:WebPartZone

ID

=

"RightRow"

runat

=

"server"

Title

=

"Right Content"

/>

</

td

>

</

tr

>

</

table

>

</

asp:Content

>

一個自定義頁面完成了。

4. 上傳檔案并更改設定

現在我們可以把剛建立好的兩個檔案上傳到Master Page Gallery下面,然後點選MyPage.aspx --> Edit properties --> Associated Content Type。Content Type Group選擇Page Layout Content Types,Content Type Name選擇Welcome Page,點選OK。

5. 建立測試頁面

Site Actions --> Create Page,進入Create Page頁面,這時,在Page Layout清單中就可以看到剛建的MyPage.aspx。你在Title中輸入Test,Page Layout選擇MyPage.aspx,點選Create,一個新頁面建立成功,接下來就是添加你自己的WebPart。

建立頁面

如何在SharePoint中建立Custom Master Page1. 安裝Features2. 自定義模闆3. 自定義布局頁面4. 上傳檔案并更改設定5. 建立測試頁面6. 釋出内容

建立成功

如何在SharePoint中建立Custom Master Page1. 安裝Features2. 自定義模闆3. 自定義布局頁面4. 上傳檔案并更改設定5. 建立測試頁面6. 釋出内容

添加webpart

如何在SharePoint中建立Custom Master Page1. 安裝Features2. 自定義模闆3. 自定義布局頁面4. 上傳檔案并更改設定5. 建立測試頁面6. 釋出内容

頁面

如何在SharePoint中建立Custom Master Page1. 安裝Features2. 自定義模闆3. 自定義布局頁面4. 上傳檔案并更改設定5. 建立測試頁面6. 釋出内容

如果要繼續添加webpart,隻要在頁面URL中加入?ControlMode=Edit&DisplayMode=Design即可進入編輯模式,如上圖所示。

6. 釋出内容

釋出所有内容,包括模闆頁、布局頁面、樣式表、圖檔等。隻有釋出,其他使用者才可以通路,否則會提示通路拒絕錯誤。釋出很簡單,點選相應項目,選擇釋出一個新版本即可,如果内容很多,一個個釋出很費勁的話,你可以寫一個小工具釋出頁可以。

繼續閱讀