none
programatically set Reset all subsites to inherit this system master page setting

    Question

  • Hi,

    I would like to create an event reciever on WebProvisioned to set the following for all the new sites

    1. Reset all subsites to inherit this system master page setting - Yes
    2. Reset all subsites to inherit this site master page setting -Yes
    3. Use Microsoft SharePoint Foundation default styles -yes

    I would like to know what are the API to be called to set the following

    Kindly Advise


    Ready for Action
    Tuesday, March 01, 2011 3:15 PM

Answers

All replies

  • Write a custom Site Collection Feature that is similar to this:

      private const string NewMasterUrl = "/_catalogs/masterpage/YourMaster.master";
    
    
      public override void FeatureActivated(SPFeatureReceiverProperties properties)
      {
       var curSite = (SPSite)properties.Feature.Parent;   
       var curWeb = curSite.RootWeb;
    
       // Create full master url
       var masterUri = new Uri(curWeb.Url + NewMasterUrl);
    
       // Master page used by all forms and pages on the site that are NOT publishing pages
       curWeb.MasterUrl = masterUri.AbsolutePath;
       // Master page used by all publishing pages on the site
       curWeb.CustomMasterUrl = masterUri.AbsolutePath;
    
       curWeb.Update();
    
       foreach (SPWeb subWeb in curSite.AllWebs)
       {
          if (subWeb.IsRootWeb) continue;
    	   Hashtable hash = subWeb .AllProperties;
      	 subWeb .MasterUrl = subWeb .ParentWeb.MasterUrl;
    	   hash["__InheritsMasterUrl"] = "True";
    
    	   subWeb .CustomMasterUrl = subWeb .ParentWeb.CustomMasterUrl;
      	 hash["__InheritsCustomMasterUrl"] = "True";
    
      	 subWeb .Update();
       }
    }

    Hope this helps.
    Regards,


    Yuri Lausberg, MCP, MCAD, MCSD, MCTS, MCPD
    Tuesday, March 01, 2011 6:05 PM
  • hello

    first of all check the following properties of SPWeb class:

    1. SPWeb.MasterUrl - url of master page used in system interface of site

    2. SPWeb.CustomMasterUrl - url of master page used in public interface of site (with publishing pages)

    3. SPWeb.AlternateCssUrl - css used in site

    see that all of them have string type. Now check the same properties of PublishingWeb class:

    1. PublishingWeb.MasterUrl

    2. PublishingWeb.CustomMasterUrl

    3. PublishingWeb.AlternateCssUrl

    see that they have InheritableStringProperty . Check this post about how to determine whether or not setting is inherited from parent site: Determine whether SPWeb inherits AlternateCssUrl from parent site or not programmatically . In order to inherit values you can use InheritableProperty.SetInherit method.


    Blog - http://sadomovalex.blogspot.com
    CAML via C# - http://camlex.codeplex.com
    Tuesday, March 01, 2011 6:26 PM
  • Write a custom Site Collection Feature that is similar to this:

     private const string NewMasterUrl = "/_catalogs/masterpage/YourMaster.master";
    
    
    
    
     public override void FeatureActivated(SPFeatureReceiverProperties properties)
    
     {
    
      var curSite = (SPSite)properties.Feature.Parent;  
    
      var curWeb = curSite.RootWeb;
    
    
    
      // Create full master url
    
      var masterUri = new Uri(curWeb.Url + NewMasterUrl);
    
    
    
      // Master page used by all forms and pages on the site that are NOT publishing pages
    
      curWeb.MasterUrl = masterUri.AbsolutePath;
    
      // Master page used by all publishing pages on the site
    
      curWeb.CustomMasterUrl = masterUri.AbsolutePath;
    
    
    
      curWeb.Update();
    
    
    
      foreach (SPWeb subWeb in curSite.AllWebs)
    
      {
    
       if (subWeb.IsRootWeb) continue;
    
    	  Hashtable hash = subWeb .AllProperties;
    
     	 subWeb .MasterUrl = subWeb .ParentWeb.MasterUrl;
    
    	  hash["__InheritsMasterUrl"] = "True";
    
    
    
    	  subWeb .CustomMasterUrl = subWeb .ParentWeb.CustomMasterUrl;
    
     	 hash["__InheritsCustomMasterUrl"] = "True";
    
    
    
     	 subWeb .Update();
    
      }
    }

    Hope this helps.
    Regards,


    Yuri Lausberg, MCP, MCAD, MCSD, MCTS, MCPD
    I think this code runs on feature activated. I need this to be run for every subsite created. On which instance of the Evenreciever i should put this code. I want it to be similar to feature stapling.

    Ready for Action
    Wednesday, March 02, 2011 5:23 AM
  • hello

    first of all check the following properties of SPWeb class:

    1. SPWeb.MasterUrl - url of master page used in system interface of site

    2. SPWeb.CustomMasterUrl - url of master page used in public interface of site (with publishing pages)

    3. SPWeb.AlternateCssUrl - css used in site

    see that all of them have string type. Now check the same properties of PublishingWeb class:

    1. PublishingWeb.MasterUrl

    2. PublishingWeb.CustomMasterUrl

    3. PublishingWeb.AlternateCssUrl

    see that they have InheritableStringProperty . Check this post about how to determine whether or not setting is inherited from parent site: Determine whether SPWeb inherits AlternateCssUrl from parent site or not programmatically . In order to inherit values you can use InheritableProperty.SetInherit method.


    Blog - http://sadomovalex.blogspot.com
    CAML via C# - http://camlex.codeplex.com
    Hi thanks, i will test it out. I need this to be run for every subsite created. On which instance of the Evenreciever i should put this code. I want it to be similar to feature stapling.


    Ready for Action
    Wednesday, March 02, 2011 5:27 AM
  • i want to apply  msaterpager and Css only new created sites not for existing sites

    please give me suggestions


    chandra

    Tuesday, May 01, 2012 5:19 PM