若想更改母板页可以代码实现,首先添加母板页Test.master,再添加Feature,Features中的内容如下:
using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
namespace Test.Features.Main
{
/// <summary>
/// 此类用于处理在激活、停用、安装、卸载和升级功能的过程中引发的事件。
/// </summary>
/// <remarks>
/// 附加到此类的 GUID 可能会在打包期间使用,不应进行修改。
/// </remarks>
[Guid("0e7d83fe-3252-4afd-b949-a1a5c1615757")]
public class MainEventReceiver : SPFeatureReceiver
{
// 取消对以下方法的注释,以便处理激活某个功能后引发的事件。
//public override void FeatureActivated(SPFeatureReceiverProperties properties)
//{
//}
取消对以下方法的注释,以便处理在停用某个功能前引发的事件。
//public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
//{
//}
// 取消对以下方法的注释,以便处理在安装某个功能后引发的事件。
//public override void FeatureInstalled(SPFeatureReceiverProperties properties)
//{
//}
// 取消对以下方法的注释,以便处理在卸载某个功能前引发的事件。
//public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
//{
//}
// 取消对以下方法的注释,以便处理在升级某个功能时引发的事件。
public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionary<string, string> parameters)
{
}
public override void FeatureActivated(
SPFeatureReceiverProperties properties)
{
SPSite siteCollection = properties.Feature.Parent as SPSite;
if (siteCollection != null)
{
SPWeb topLevelSite = siteCollection.RootWeb;
// Calculate relative path to site from Web Application root.
string WebAppRelativePath = topLevelSite.ServerRelativeUrl;
if (!WebAppRelativePath.EndsWith("/"))
{
WebAppRelativePath += "/";
}
// Enumerate through each site and apply branding.
foreach (SPWeb site in siteCollection.AllWebs)
{
site.MasterUrl = WebAppRelativePath +
"_catalogs/masterpage/Test.master";
site.CustomMasterUrl = WebAppRelativePath +
"_catalogs/masterpage/Test.master";
site.AlternateCssUrl = WebAppRelativePath +
"Style/Test/Styles.css";
site.SiteLogoUrl = WebAppRelativePath +
"Style/Test/Images/Background.jpg";
site.UIVersion = 4;
site.Update();
}
}
}
public override void FeatureDeactivating(
SPFeatureReceiverProperties properties)
{
SPSite siteCollection = properties.Feature.Parent as SPSite;
if (siteCollection != null)
{
SPWeb topLevelSite = siteCollection.RootWeb;
// Calculate relative path of site from Web Application root.
string WebAppRelativePath = topLevelSite.ServerRelativeUrl;
if (!WebAppRelativePath.EndsWith("/"))
{
WebAppRelativePath += "/";
}
// Enumerate through each site and remove custom branding.
foreach (SPWeb site in siteCollection.AllWebs)
{
site.MasterUrl = WebAppRelativePath +
"_catalogs/masterpage/v4.master";
site.CustomMasterUrl = WebAppRelativePath +
"_catalogs/masterpage/v4.master";
site.AlternateCssUrl = "";
site.SiteLogoUrl = "";
site.Update();
}
}
}
}
}
这样部署成功后,点击网站操作——网站设置——网站集功能,激活所建Feature即可更改母板页