我正在创建一个站点功能Reciever,该Reciever在Root Web上设置自定义主页。我还希望将主页设置在根上,以继承所有子站点。确保此(使用.NET)的最优雅方法是什么?

(显然,我可以迭代所有子站点并手动设置它。)

有帮助吗?

解决方案

有一种更简单的方法可以使用SharePoint API进行操作:

SPWeb web = SPContext.Current.Web;
PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
publishingWeb.CustomMasterUrl = "/_catalogs/masterpage/mycustom.master";
publishingWeb.CustomMasterUrl.SetInherit(true, true);
publishingWeb.Update();

其他提示

我认为我们能做的最好的就是在特征反应方法中的以下内容。

foreach (SPWeb site in siteCollection.AllWebs) 
{
  site.MasterUrl = "/_catalogs/masterpage/mycustom.master";
  site.CustomMasterUrl ="/_catalogs/masterpage/mycustom.master";
  site.Update();
  site.Dispose();
}
private void SetMaster(SPWeb web, string masterpagePath, string custommasterpagePath) 
{
    web.CustomMasterUrl = masterpagePath;
    web.MasterUrl = custommasterpagePath;
    web.Update();

    foreach(SPWeb child in web.Webs) 
    {
        try {
            SetMaster(child, masterpage, custommasterpage);
        } 
        finally
        {
            if(child != null) child.Dispose();
        }
    }
}

称此通过spsite.rootweb,并指定通往主页的路径。它将在网站集合中的rootweb下方的所有站点上循环(即所有这些站点!)

请注意,您可能需要考虑是否使用以下网站 不同的主页 作为 这可能引起问题, ,特别是在开会工作区,但可能是其他工作区。

您可能还需要考虑 将原始主页存储在物业袋中 对于网络,因此您可以在以后还原它们(例如功能停用)

你可能想 确保关闭主题 并且不要干扰您的外观和感觉。

http://msdn.microsoft.com/en-us/library/gg447066(v=office.14).aspx

这将按事件接收器提供toplevel网站主页...

许可以下: CC-BY-SA归因
scroll top