私の質問を公開しましょう: ルートページ、マスターページ、および多くのサブサイトがあります。ルートサイトマスターページを使用する(継承する)ものもあれば、ルートサイトマスターページを使用しないものもあります。
ルートサイトMPをそのような機能イベントレシーバーで更新すると:
SPWeb w = ((SPSite)properties.Feature.Parent).OpenWeb();
Uri masterUri = new Uri(w.Url + "/_catalogs/masterpage/AdventureWorks.master");
//MasterPage used by publishing pages
w.CustomMasterUrl = masterUri.AbsolutePath;
w.AllowUnsafeUpdates = true;
w.Update();
... ルートサイトのマスターページは更新されますが、ルートサイトのマスターページを継承するサブサイトは更新されません。サブサイトのサイトマスターページ設定ページに移動すると、[このサイトの親からサイトマスターページを継承する]ラジオボタンが十分にチェックされます。
「サイトマスターページの設定」ページから新しいMasterPageを適用すると、この問題が発生しません。
詳細:公開サイトのルートサイト、および "SharePoint Server Publishing Infrastructure"および "SharePoint Server Publishing"機能が実行されています。
私は何かが恋しいですか?
回答:
回答№1は1それでも1か月たっても応答がありません:/だから、サブサイトのすべてのマスターページを更新するメカニズムはないと思います。 そのため、次のように機能起動イベントレシーバーを更新しました。
using (SPWeb w = ((SPSite)properties.Feature.Parent).OpenWeb())
{
Uri masterUri = new Uri(w.Url + "/_catalogs/masterpage/AdventureWorks.master");
w.CustomMasterUrl = masterUri.AbsolutePath;
w.AllowUnsafeUpdates = true;
w.Update();
foreach (SPWeb ww in w.Site.AllWebs)
{
if (!ww.IsRootWeb)
{
Hashtable hash = ww.AllProperties;
if (string.Compare(hash["__InheritsCustomMasterUrl"].ToString(), "True", true) == 0)
{
ww.CustomMasterUrl = masterUri.AbsolutePath;
ww.AllowUnsafeUpdates = true;
ww.Update();
}
}
}
}
目標は、subwebがmasterPageを継承するかどうかをテストすることです(サブWebごとに)。その場合、CustomMasterUrlプロパティを更新する必要があります。
回答№2の場合は0
これを使用して、ルートおよびすべてのサブWebにマスターページを設定します。
var web = site.RootWeb;
web.MasterUrl = web.CustomMasterUrl = SPUtility.ConcatUrls(web.ServerRelativeUrl, "_catalogs/mymaster.master");
web.Update();
foreach (SPWeb subWeb in site.AllWebs)
{
using (subWeb)
{
if (subWeb.IsRootWeb) continue;
var hash = subWeb.AllProperties;
subWeb.MasterUrl = subWeb.CustomMasterUrl = web.MasterUrl;
hash["__InheritsMasterUrl"] = "True";
hash["__InheritsCustomMasterUrl"] = "True";
subWeb.Update();
}
}