但是,微軟警告我們不要 編輯「default.master」,因爲它會通過 下一個服務包 或補丁覆蓋。
複製&粘貼具有不同名稱的新主頁並將其用作默認頁面。使用SharePoint設計器或以編程方式設置SPWeb.MasterUrl和/或SPWeb.CustomMasterPage。
對於這一點,我有2個特點
- 一到當前網站上設置自定義母版頁
- 其他一個對所有網+主食功能激活之前的功能,新創建的網站的
Project http://img251.imageshack.us/img251/7351/ss20100312093605.png (MWSBalticovo是爲了滿足工作空間 - 他們有不同的母版)
國營石油網使用自定義母版頁的單個網站的編輯功能。
我有我的自定義主頁功能打包:
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="BalticovoMasterPages" List="116" Url="_catalogs/masterpage" RootWebOnly="TRUE" Path="MasterPages">
<File Url="Balticovo.master" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE">
<Property Name="ContentType" Value="$Resources:core,MasterPage;"/>
<Property Name="MasterPageDescription" Value="$Resources:Balticovo,BalticovoMasterPageDescription;"/>
</File>
<File Url="MWSBalticovo.master" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE">
<Property Name="ContentType" Value="$Resources:core,MasterPage;"/>
<Property Name="MasterPageDescription" Value="$Resources:Balticovo,MWSBalticovoMasterPageDescription;"/>
</File>
</Module>
</Elements>
而且FeatureReceiver:
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWeb web = properties.Feature.Parent as SPWeb;
string masterUrl = "/_catalogs/masterpage/Balticovo.master";
string mwsMasterUrl = "/_catalogs/masterpage/MWSBalticovo.master";
if (web.CustomMasterUrl.ToLower().Contains("/mws")) //meeting workspace
web.CustomMasterUrl = mwsMasterUrl;
else
web.CustomMasterUrl = masterUrl;
web.MasterUrl = masterUrl;
web.Update();
}
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
SPWeb web = properties.Feature.Parent as SPWeb;
web.MasterUrl = "/_catalogs/masterpage/default.master";
if (web.CustomMasterUrl.ToLower().Contains("/mws")) //meetng workspace
web.CustomMasterUrl = "/_catalogs/masterpage/MWSdefault.master";
else
web.CustomMasterUrl = "/_catalogs/masterpage/default.master";
web.Update();
}
第二站點範圍的功能,使以前的所有功能
元素。XML(激活第一個功能上的新創建的網站的,但在現有的將不激活):
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<FeatureSiteTemplateAssociation
TemplateName="GLOBAL"
Id="{227c6aed-f66b-482d-aea8-a2af3ca203b7}" />
</Elements>
FeatureReceiver(激活現有的網1功能):
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
Guid masterPageFeatureId = new Guid("{227c6aed-f66b-482d-aea8-a2af3ca203b7}");
SPSite site = properties.Feature.Parent as SPSite;
SPWebCollection webs = site.AllWebs;
foreach (SPWeb web in webs)
{
try
{
if (web.Features[masterPageFeatureId] == null)
web.Features.Add(masterPageFeatureId);
}
catch (InvalidOperationException) //target feature not yet installed
{ throw; }
catch (SPException) { } //If feature could not be activated.
finally
{
if (web != null)
web.Dispose();
}
}
}
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
Guid masterPageFeatureId = new Guid("{227c6aed-f66b-482d-aea8-a2af3ca203b7}");
SPSite site = properties.Feature.Parent as SPSite;
SPWebCollection webs = site.AllWebs;
foreach (SPWeb web in webs)
{
try
{
if (web.Features[masterPageFeatureId] == null)
web.Features.Remove(masterPageFeatureId);
}
catch (InvalidOperationException) { }
catch (SPException) { }
finally
{
if (web != null)
web.Dispose();
}
}
}