sharepoint主題樣式定製

主題樣式

簡介:

    SharePoint2013關於主題樣式的問題,相信大家都比較頭疼,其實SharePoint有很好的解決方法。這裏介紹一個自定義主題樣式的方法。通過一個feature選擇適合自己的樣式,其它網站集只要激活該feature就能應用該主題。

實現:

   添加模板頁:

1、  添加一個module元素

2、  設置Elements

<span style="font-size:18px;"><?xml version="1.0"encoding="utf-8"?>

<Elementsxmlns="http://schemas.microsoft.com/sharepoint/">

 <Module Name="MasterPage"Url="_catalogs/masterpage">

   <File Url="MyMasterPage.master"Type="GhostableInLibrary"

         Path="MasterPage\MyMasterPage.master"IgnoreIfAlreadyExists="true">

     <Property Name="UIVersion" Value="15" />

     <Property Name="ContentTypeId" Value="0x010105"/>

   </File>
 </Module>
</Elements></span>


添加主題樣式

1、  添加一個module元素

2、  在當前目錄下上傳你的樣式文件 這裏叫(MyTheme.spcolor

3、  寫Elements元素

<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

  <Module Name="Theme" Url="_catalogs/theme/15">

    <File Path="Theme\MyTheme.spcolor" Url="MyTheme.spcolor" 

          Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" />

  </Module>

</Elements></span>

添加字體設置

在上一個module中添加字體文件(MyFontScheme.spfont

Element中添加一行元素

<span style="font-size:18px;"><File Path=”Theme\MyFontScheme.spfont” Url=”MyFontScheme.spfont”

Type=”GhostableInLibrary” IgnoreIfAlreadyExists=”TRUE” /></span>

添加功能

添加feature,再爲其添加監聽事件。

將上面做的module添加到feature中去,在feature正激活事件中寫。

 

<span style="font-size:18px;">publicoverridevoid FeatureActivated(SPFeatureReceiverProperties properties)

        {

   conststring ThemeUrl = "_catalogs/theme/15/bingoPalette012.spcolor";

            conststring FontSchemeUrl = "_catalogs/theme/15/bingofontscheme002.spfont";

            var site =properties.Feature.Parent asSPSite;

            if (site != null)

            {
                var serverRelativeUrl =site.RootWeb.ServerRelativeUrl;

               site.RootWeb.ApplyTheme(serverRelativeUrl + ThemeUrl, serverRelativeUrl+ FontSchemeUrl, null, true);                       

            }
}</span>

這裏的feature是向site級別部署的。

注意

   當前站點的http://主機ip/_catalogs/theme/15/bingoPalette012.spcolor

要能找文件,如果找不到,將文件傳上去。

總結

    對於陌生的東西比較害怕,其實都是紙老虎。多看些,多瞭解些。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章