Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am using sharepoint 2010 and vs2010.

I have created a custom webtemplates and begin from a copy of a teamsite. In my onet.xml I see the following site feature elements:

<SiteFeatures>
    <!-- BasicWebParts Feature -->
    <Feature ID="00BFEA71-1C5E-4A24-B310-BA51C3EB7A57" />
    <!-- Three-state Workflow Feature -->
    <Feature ID="FDE5D850-671E-4143-950A-87B473922DC7" />
  </SiteFeatures>

I created a new site collection from the site template "publish site" I deployed my custom web template to this site collection. I create a new site and select my custom web template. I got some error: "the site template requires that the feature fde5d850-671e-4143-950a-87b473922dc7 be activated in the site collection"

When I go to the site collection features and enable this feature "Three-state workflow : fde5d850-671e-4143-950a-87b473922dc7" it works.

But I dont understand, why I need to do this manual?? In my onet.xml of my custom web template I have declare this feature to be activated in the sitefeature element.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

The onet.xml file is divided into two parts, first is the "SiteFeatures" and the second called "WebFeatures". The "SiteFeatures" Section that holds the site features starts activating all the features only when creating a site collection. The "WebFeatures" Section that holds the web features starts activating all the web scoped features only when creating a site (like you tried).

The solution is to trigger the Site collection scoped feature using web scoped feature.

The steps are:

A) Create an empty web scoped feature and in the "FeatureActivated" event add the following code.

  public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            try
            {
                //Ensure that scope is correctly set
                if (properties.Feature.Parent is SPWeb)
                {
                    SPWeb web = (SPWeb)properties.Feature.Parent;


                    foreach (SPFeatureProperty property in properties.Feature.Properties)
                    {
                        Guid featureGuid = new Guid(property.Value);
                        //Verify feature status
                        SPFeature feature = web.Site.Features[featureGuid];
                        if (feature == null)
                        {
                            //Activate site collection scoped feature, if requested and not currently activated
                            web.Site.Features.Add(featureGuid);
                        }
                    }
                }
            }
            catch (Exception ex)
            {}
        }

B) In the onet.xml file in the "WebFeature" Node add the following xml

 <WebFeatures>
       <!-- Custom Site collection scoped feature activation -->
        <Feature ID="YourEmptyFeatureGuid">
          <Properties xmlns="http://schemas.microsoft.com/sharepoint/">
            <Property Key="SiteScopedGUID" Value="FDE5D850-671E-4143-950A-87B473922DC7"/>
          </Properties>
        </Feature>
 </WebFeatures>
  • In the Feature ID element add your empty feature's ID
  • In the Property Key="SiteScopedGUID" element in the value add the site collection feature id that you want to activate.

That's it. deploy your solution and it should work.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.