Navigate Up
Sign In
Supporters of Developer
Web

SharePoint: Can't Activate Site Collection Feature When Creating New Site From a Custom Web Template

Item is currently unrated. Press SHIFT+ENTER to rate this item.1 star selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+ESCAPE to leave rating submit mode.2 stars selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.3 stars selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.4 stars selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.5 stars selected. Press SHIFT+ENTER to submit. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.

You may also be interested in: SharePoint-based solutions by B&R Business Solutions

 

Editor's note: Contributor Alex Choroshin is a Sharepoint Team Leader at Bank Leumi. Follow him @choroshin

The onet.xml file is basically divided into two parts, first is the "SiteFeatures" element and the second element is 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.

Scenario: you created a custom web template and deployed the solution but when trying to create a site from your custom web template you get the following error "the site template requires that the feature {GUID} be activated in the site collection". Of course you can always activate the site collection scoped feature manually but, let's be serious; you need all the necessary features to be automatically activated.

Solution: When creating a site you need to trigger the site collection scoped feature using a web scoped feature.

The steps are:

A) Create an empty web scoped feature and in the "FeatureActivated" Event Receiver 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" Element, 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="YourSiteCollectionFeatureID"/>
         </Properties>
       </Feature>
</WebFeatures>

  • In the Feature ID element add your empty feature's ID
  • In the Property Key="SiteScopedGUID" element add the site collection feature id that you want to activate.

Hope you’ll find this post helpful

Categories: dev; C#; 2010

Comments

china wholesale

china wholesale

Posted 01-Jul-2013 by china wholesale
NammE

Activating a Feature in Site collection

Hi ,
 
We've created a feature to change the format of the alert template of a list. Unfortunately, it only works on the Custom list and not on the default list. (Ex.Announcement, Task, Links, Calendars, etc..). We found out that during the activation, those default list was not included on the site collection level.
 
We try to put the code on the Activated and list Added events. We tried stapling but have no success.
 
Is there a way or any event we can use so that we can put the activation code on those default list?
 
Need your experties ASAP pls :)
 

Posted 05-Aug-2013 by NammE
NammE

Activating a Feature in Site collection

Hi ,
 
We've created a feature to change the format of the alert template of a list. Unfortunately, it only works on the Custom list and not on the default list. (Ex.Announcement, Task, Links, Calendars, etc..). We found out that during the activation, those default list was not included on the site collection level.
 
We try to put the code on the Activated and list Added events. We tried stapling but have no success.
 
Is there a way or any event we can use so that we can put the activation code on those default list?
 
Need your experties ASAP pls :)
 

Posted 05-Aug-2013 by NammE
NammE

Activating a Feature in Site collection

Hi ,
 
We've created a feature to change the format of the alert template of a list. Unfortunately, it only works on the Custom list and not on the default list. (Ex.Announcement, Task, Links, Calendars, etc..). We found out that during the activation, those default list was not included on the site collection level.
 
We try to put the code on the Activated and list Added events. We tried stapling but have no success.
 
Is there a way or any event we can use so that we can put the activation code on those default list?
 
Need your experties ASAP pls :)
 

Posted 05-Aug-2013 by NammE
NammE

Activating a Feature in Site collection

Hi ,
 
We've created a feature to change the format of the alert template of a list. Unfortunately, it only works on the Custom list and not on the default list. (Ex.Announcement, Task, Links, Calendars, etc..). We found out that during the activation, those default list was not included on the site collection level.
 
We try to put the code on the Activated and list Added events. We tried stapling but have no success.
 
Is there a way or any event we can use so that we can put the activation code on those default list?
 
Need your experties ASAP pls :)
 

Posted 05-Aug-2013 by NammE
calça montaria

great way of bring such topic to discussion

This is a nice post in an interesting line of content.Thanks for sharing this article, great way of bring such topic to discussion. - Comprando calça montaria

Posted 28-Oct-2013 by calça montaria
letting agent web design

infi

They adorn a succeed of uncommon highways to bear in touching, particularly electronic remit, conversation as well as jail phone. Sacraments is usually rapid alongsides similarly nice, as well.

Posted 12-Dec-2013 by letting agent web design
sina

paper

In fact, this item disgrace looms to the ache span inclusive people portrait on the industry besides determination decelerate up the best paper writing service fame on the pattern plus consumers’ ego-hope interior the work. So, the partnership power eradicate a hearty discover on the shop.

Posted 14-Dec-2013 by sina
Andyu

Really impressed!

Really impressed! Everything is very, very clear, open is a description of the problem.brazilian hair

Posted 18-Feb-2014 by Andyu
John Jessie

John Jessie

Better content. I read one yesterday and truly this one is way better.black leather jacket for men

Posted 26-Mar-2014 by John Jessie
replica louis vuitton handbags

John Jane

Just give it a chance, and you'll find that the city Women Louis Vuitton Artsy MM-Brown replica louis vuitton handbags Louis Vuitton M40249 has so much Women Louis Vuitton Alma MM-Brown Louis Vuitton M53150 more to offer than crime and fear.

Posted 10-Apr-2014 by replica louis vuitton handbags

Notify me of comments to this article

E-mail:
   

Add Comment

Title:

 
Comment:
Email:

   


Name:

 
Url: