2011-04-01 90 views
1

我已創建了作爲功能部署的自定義主頁面。我正在使用SP Foundation而不是SP Server。將自定義主頁面應用於所有SP基金會網站

我已經激活了該功能,但masterpage只應用於頂級網站。有人可以讓我知道我的事件接收器做了什麼問題。

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/custom.master"; 
       site.CustomMasterUrl = WebAppRelativePath + "_catalogs/masterpage/custom.master"; 
       site.Update(); 
      } 
     } 
    } 

任何幫助將是偉大的!

回答