Friday, August 1, 2014

How to provision a page at SiteCollection level

If you just need to do a one shot (only adding it once on the parent web) ,you can use the first idea I had


1) create a new scoped web feature where you will add the page you want to provision on the parent web


2) in your current feature, add an event receiver with this code



public class Feature1EventReceiver : SPFeatureReceiver
{
// Uncomment the method below to handle the event raised after a feature has been activated.

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWeb currentWeb = properties.Feature.Parent as SPWeb;
Guid parentWebFeatureID = new Guid("your parent web feature id");
if (currentWeb.ParentWeb != null)
{
if (currentWeb.ParentWeb.Features[parentWebFeatureID] == null)
currentWeb.ParentWeb.Features.Add(parentWebFeatureID);

}
}

it will test if your feature is already activated on parent web, if not it will activate it


Edit : if you want to be sure that it's targeting the rootweb , use



currentWeb.Site.RootWeb

instead of



currentWeb.ParentWeb





Best regards, Christopher.

Blog | Mail

Please remember to click "Mark As Answer" if a post solves your problem or "Vote As Helpful" if it was useful.

Why mark as answer?




No comments:

Post a Comment