Answered by:
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
- Reset all subsites to inherit this system master page setting - Yes
- Reset all subsites to inherit this site master page setting -Yes
- 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 ActionTuesday, March 1, 2011 3:15 PM
Answers
-
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- Edited by Yuri Lausberg Tuesday, March 1, 2011 6:09 PM typo in code
- Marked as answer by Xue-Mei Chang-MSFT Friday, March 11, 2011 8:58 AM
Tuesday, March 1, 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:
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- Marked as answer by Xue-Mei Chang-MSFT Friday, March 11, 2011 8:58 AM
Tuesday, March 1, 2011 6:26 PM
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- Edited by Yuri Lausberg Tuesday, March 1, 2011 6:09 PM typo in code
- Marked as answer by Xue-Mei Chang-MSFT Friday, March 11, 2011 8:58 AM
Tuesday, March 1, 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:
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- Marked as answer by Xue-Mei Chang-MSFT Friday, March 11, 2011 8:58 AM
Tuesday, March 1, 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
Ready for ActionWednesday, March 2, 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:
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
Ready for ActionWednesday, March 2, 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 1, 2012 5:19 PM